#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ds[3] = {-1, -1, -1};
  int cs, cc;
  for (int i = 0; i < m; i++) {
    cin >> cs >> cc;
    if (ds[n - cs] >= 0 && ds[n - cs] != cc) ds[0] = ds[1] = ds[2] = 11;
    ds[n - cs] = max(ds[n - cs], cc);
  }
  if (ds[0] > 10 || ds[1] > 10 || ds[2] > 10)
    cout << "-1" << endl;
  else {
    if (ds[n - 1] == 0)
      cout << "-1" << endl;
    else {
      ds[0] = max(ds[0], (int)(n == 1));
      ds[1] = max(ds[1], (int)(n == 2));
      ds[2] = max(ds[2], (int)(n == 3));
      cout << (ds[0] + ds[1] * 10 + ds[2] * 100) << endl;
    }
  }
  return 0;
}
