#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, mcount = 0;
  bool doublecheck = false;
  int num[1005] = {};
  int ketacheck[5] = {};
  bool bketacheck[5];
  for (int i = 0; i < 5; i++) {
    bketacheck[i] = false;
  }
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (bketacheck[s] && ketacheck[s] != c) {
      doublecheck = true;
    }
    ketacheck[s] = c;
    bketacheck[s] = true;
    for (int j = 0; j < 1000; j++) {
      int cn = j;
      int nownum;
      for (int k = 0; k < N - s + 1; k++) {
        nownum = cn % 10;
        cn /= 10;
      }
      if (nownum == c) {
        num[j]++;
      }
    }
    mcount++;
  }
  if (doublecheck) {
    cout << -1 << endl;
    return 0;
  }
  int ans = -1;
  for (int i = 0; i < 1000; i++) {
    if (num[i] != 0 && num[i] == mcount) {
      ans = i;
      break;
    }
  }
  if (N >= 2 && ans == 0) ans = -1;
  cout << ans << endl;
  return 0;
}
