#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, m;
  cin >> n >> m;
  vector<pair<long long, long long>> check;
  for (long long i = 0; i <= 1000; i++) {
    check.emplace_back(i, 0);
  }
  if (m > 0) {
    for (long long i = 0; i < m; i++) {
      long long s, c;
      cin >> s >> c;
      for (long long i = 1; i < 1000; i++) {
        string str = to_string(i);
        string cc = to_string(c);
        if (str[s - 1] != cc[0] || str.length() != n) check[i].second = 1;
      }
    }
    for (long long i = 1; i < 1000; i++) {
      if (check[i].second == 0) {
        cout << i << endl;
        break;
      }
      if (i == 999) cout << -1 << endl;
    }
  } else if (m == 0) {
    if (n == 1)
      cout << 0 << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
