#include <bits/stdc++.h>
using namespace std;
set<pair<long long int, long long int> > se;
int32_t main() {
  long long int n, m, pos, t;
  cin >> n >> m;
  for (long long int i = 1; i <= m; i++) {
    cin >> pos >> t;
    se.insert({pos, t});
  }
  string s;
  for (long long int i = 0;; i++) {
    s = to_string(i);
    if (s.length() > n) {
      break;
    }
    for (auto x : se) {
      if (!(s[x.first - 1] == ('0' + x.second))) {
        goto fin;
      }
    }
    cout << s;
    return 0;
  fin:
    1;
  }
  cout << -1;
}
