#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S, C;
  int s, c;
  int st, ed;
  if (N == 1) {
    st = 0;
    ed = 10;
  } else if (N == 2) {
    st = 10;
    ed = 100;
  } else {
    st = 100;
    ed = 1000;
  }
  for (int i = 0; i < M; ++i) {
    cin >> s >> c;
    S.push_back(s);
    C.push_back(c);
  }
  int ans = -1;
  bool ok;
  for (int i = st; i < ed; ++i) {
    ok = true;
    for (int m = 0; m < M; ++m) {
      if (S[m] == 1) {
        if (i / 100 != C[m]) ok = false;
      } else if (S[m] == 2) {
        if ((i % 100) / 10 != C[m]) ok = false;
      } else {
        if (i % 10 != C[m]) ok = false;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
