#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[5], c[5];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i <= 999; i++) {
    string x = to_string(i);
    if (x.size() != N) {
      continue;
    }
    for (int j = 0; j < M; j++) {
      if (x[s[j]] != (char)('0' + c[j])) {
        break;
      }
      if (j == M - 1) {
        cout << x << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
