#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  set<int> b;
  int c = 0;
  map<int, int> ch;
  for (int i = 0; i < m; i++) {
    int d, e;
    cin >> d >> e;
    a[i] = make_pair(d, e);
    if (ch.count(d) && ch[d] != e) c = -1;
  }
  unique(a.begin(), a.end());
  sort(a.begin(), a.end());
  int t = 1;
  for (int i = 0; i < n; i++) {
    t *= 10;
    ch[0] *= 10;
  }
  bool ans = true;
  if (c > -1) {
    for (int i = ch[0]; i < t; i++) {
      int k = i;
      string t = to_string(k);
      for (int j = 0; j < m; j++) {
        if (t[a[i].first - 1] != a[i].second) ans = true;
        c = i;
      }
      if (ans) break;
    }
  }
  cout << c << endl;
}
