#include <bits/stdc++.h>
using namespace std;
bool ok(int r, int n, vector<int> f) {
  for (int i = 0; i < (n); i++) {
    if (r % 10 != f[2 - i] && f[2 - i] != -1) return false;
    r /= 10;
  }
  return true;
}
signed main() {
  int n, m, s, c, r = 0;
  bool no = false;
  cin >> n >> m;
  vector<int> f(n, -1);
  for (int i = 0; i < (m); i++) {
    cin >> s;
    cin >> c;
    if ((f[s - 1] != -1 && c != f[s - 1]) || (s == 1 && c == 0)) {
      no = true;
      break;
    } else {
      f[s - 1] = c;
    }
  }
  if (no) {
    cout << -1 << endl;
    return 0;
  }
  while (!ok(r, n, f)) r++;
  cout << r << endl;
  return 0;
}
