#include <bits/stdc++.h>
using namespace std;
int n, m, a[3] = {-1, -1, -1};
int main() {
  cin >> n >> m;
  for (int i = 0; i < (int)(m); i++) {
    int s, c;
    cin >> s >> c;
    int d = n - s;
    if ((a[d] != -1 && a[d] != c) || (n > 1 && s == 1 && c == 0)) {
      cout << -1 << endl;
      return 0;
    }
    a[d] = c;
  }
  for (int i = 0; i < (int)(3); i++) cerr << a[i] << " ";
  cerr << endl;
  for (int i = 0; i < (int)(pow(10, n)); i++) {
    bool flag = true;
    int num[3] = {i % 10, (i / 10) % 10, (i / 100)};
    for (int j = 0; j < (int)(n); j++) {
      if (a[j] != -1 && a[j] != num[j]) flag = false;
    }
    if (flag) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
