#include <bits/stdc++.h>
using namespace std;
int main() {
  long n, m;
  cin >> n >> m;
  vector<vector<int>> sc(10, vector<int>(3));
  for (int i = 0; i < m; i++) {
    cin >> sc[i][1] >> sc[i][2];
  }
  bool chkflg;
  int a[4];
  for (int i = 0; i < 1000; i++) {
    chkflg = true;
    int k;
    k = i;
    a[n] = k % 10;
    k /= 10;
    if (k != 0) {
      a[n - 1] = k % 10;
      k /= 10;
      if (k != 0) {
        a[n - 2] = k % 10;
        k /= 10;
      }
    }
    for (int j = 0; j < m; j++) {
      if (sc[j][2] != a[sc[j][1]]) {
        chkflg = false;
        break;
      }
    }
    if (chkflg == true) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
