#include <bits/stdc++.h>
using namespace std;
signed main() {
  int n, m;
  cin >> n >> m;
  if (m == 0) {
    cout << -1 << endl;
    ;
  }
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  int H = 1, L = 1;
  for (int i = 0; i < (int)(n - 1); i++) L *= 10;
  H = L * 10;
  for (int i = L; i < H; i++) {
    bool ok = true;
    for (int j = 0; j < (int)(m); j++) {
      int v = i;
      for (int k = 0; k < (int)(n - s[j]); k++) v /= 10;
      if (v % 10 == c[j]) {
      } else {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      ;
      return 0;
    }
  }
  cout << -1 << endl;
  ;
  return 0;
}
