#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 ((cs == 1 && cc == 0 && n > 1) ||
        (ds[cs - 1] >= 0 && ds[cs - 1] != cc)) {
      ds[0] = ds[1] = ds[2] = 11;
    }
    ds[cs - 1] = max(ds[cs - 1], cc);
  }
  for (int i = 0; i < 3; i++) {
    if (i == 0 && ds[i] < 0) ds[i] = 1;
    ds[i] = max(ds[i], 0);
  }
  if (ds[0] > 10)
    cout << "-1" << endl;
  else {
    if (n == 3) cout << (ds[0] * 100 + ds[1] * 10 + ds[2]) << endl;
    if (n == 2) cout << (ds[0] * 10 + ds[1]) << endl;
    if (n == 1) cout << (ds[0]) << endl;
  }
  return 0;
}
