#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans = 0, check = 0;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (; ans <= 999; ans++) {
    int ac = ans;
    for (int i = 0; i < N - 1; i++) {
      ac /= 10;
    }
    if (ac < 1 && ans != 0 || ac > 9) {
      continue;
    }
    int checker = 1;
    for (int i = 0; i < M; i++) {
      ac = ans;
      for (int j = 0; j < N - s.at(i); j++) {
        ac /= 10;
      }
      if (ac % 10 != c.at(i)) {
        checker = 0;
      }
    }
    if (checker == 1) {
      cout << ans << endl;
      check = 1;
      break;
    }
  }
  if (check == 0) {
    cout << -1 << endl;
  }
}
