#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m, i, s[6], c[6], d[4], t, k;
  cin >> n >> m;
  for (i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (t = 0; t < 1000; t++) {
    vector<int> d;
    k = t;
    while (k > 0) {
      d.push_back(k % 10);
      k /= 10;
    }
    for (i = 0; i < m; i++) {
      if (s[i] > d.size()) break;
      if (d[d.size() - s[i]] != c[i]) break;
    }
    if (i == m) break;
  }
  if (t == 1000)
    cout << -1 << endl;
  else
    cout << t << endl;
  return 0;
}
