#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, m;
  cin >> n >> m;
  long long len = pow(10, n);
  string str[len + 1];
  char check[len + 1];
  for (long long i = 1; i <= len; i++) {
    str[i] = to_string(i);
    check[i] = 'o';
  }
  long long ans = 1e9;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    for (long long i = 1; i <= len; i++) {
      string aa = to_string(c);
      if (str[i][s - 1] != aa[0]) check[i] = 'x';
    }
  }
  bool cc = true;
  for (long long i = 1; i <= len; i++) {
    if (check[i] == 'o') {
      cc = false;
      cout << i << endl;
      break;
    }
  }
  if (cc == true) cout << -1 << endl;
  return 0;
}
