#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (s.at(i) == 1 && c.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  int A, B, C;
  bool ok;
  for (int i = 0; i < 1000; i++) {
    A = i / 100;
    B = (i - A * 100) / 10;
    C = i % 10;
    ok = true;
    for (int j = 0; j < m; j++) {
      if (s.at(j) == 1 && A != c.at(j)) {
        ok = false;
        break;
      } else if (s.at(j) == 2 && B != c.at(j)) {
        ok = false;
        break;
      } else if (s.at(j) == 3 && C != c.at(j)) {
        ok = false;
        break;
      }
      if (ok && j == m - 1) {
        cout << A * 100 + B * 10 + C << endl;
        break;
      }
    }
    if (ok) break;
  }
  if (!ok) cout << -1 << endl;
}
