#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  bool firstZero = false;
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == '0') firstZero = true;
  }
  int ans = -1;
  if (n != 0 && firstZero) {
    cout << ans << endl;
    return 0;
  }
  for (int i = 0; i < 1000; i++) {
    string tmp_s = to_string(i);
    bool ok = true;
    for (int i = 0; i < m; i++) {
      if (tmp_s[s[i] - 1] != c[i]) {
        ok = false;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
