#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int res = -1;
  string current;
  for (int i = 0; i < 1000; i++) {
    current = to_string(i);
    if (current.size() != n) continue;
    int j = 0;
    for (int j = 0; j < m; j++) {
      int s;
      cin >> s, s--;
      char c;
      cin >> c;
      if (current[s] != c) break;
    }
    if (j == m) {
      res = i;
      break;
    }
  }
  cout << res << endl;
  return 0;
}
