#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(n), c(n);
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  long long ans = -1;
  for (long long i = 0; i <= 999; i++) {
    string x = to_string(i);
    long long N = x.size();
    bool flag = true;
    for (long long j = 0; j < m; j++) {
      if (N != n) {
        flag = false;
        break;
      }
      if (x[s[j]] - '0' != c[j]) {
        flag = false;
        break;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans << '\n';
}
