#include <bits/stdc++.h>
using namespace std;
int n, m, nr = 0, s[11], c[11];
bool ok(int nr) {
  int I = nr / 100, II = nr / 10 % 10, III = nr % 10;
  int a[4];
  a[1] = I;
  a[2] = II;
  a[3] = III;
  for (int i = 1; i <= m; ++i) {
    if (a[s[i]] != c[i]) {
      return 0;
    }
  }
  return 1;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 1; i <= 9; ++i) {
    if (n >= 2) {
      for (int j = 0; j <= 9; ++j) {
        if (n == 3) {
          for (int k = 0; k <= 9; ++k) {
            nr = 100 * i + 10 * j + k;
            if (ok(nr)) {
              cout << nr;
              return 0;
            }
          }
        } else {
          nr = 10 * i + j;
          if (ok(nr)) {
            cout << nr;
            return 0;
          }
        }
      }
    } else if (ok(i)) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
