#include <bits/stdc++.h>
using namespace std;
long long digit(long long n) {
  if (n == 0) return 1;
  long long ret = 0;
  while (n > 0) {
    ret++;
    n /= 10;
  }
  return ret;
}
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (long long i = 0; i <= 999; i++) {
    if (digit(i) == n) {
      bool flag = true;
      for (long long j = 0; j < m; j++) {
        if (s[j] == 1) {
          if (i / 100 != c[j]) flag = false;
        } else if (s[j] == 2) {
          if ((i / 10) % 10 != c[j]) flag = false;
        } else {
          if (i % 10 != c[j]) flag = false;
        }
      }
      if (flag) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
