#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, start, end, s, c;
  cin >> n >> m;
  start = pow(10, n - 1);
  end = pow(10, n);
  vector<int> constraint(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    s--;
    if (constraint[s] != -1 && constraint[s] != c) {
      cout << "-1" << endl;
      return 0;
    }
    constraint[s] = c;
  }
  bool ok;
  string tmp;
  for (int i = start; i <= end; i++) {
    ok = true;
    tmp = to_string(i);
    for (int j = 0; j < (int)(3); j++)
      if (constraint[j] != -1 && (char)(constraint[j] + '0') != tmp[j])
        ok = false;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
