#include <bits/stdc++.h>
const int MOD{int(1e9 + 7)};
const int inf{2100000000};
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int ans = -1;
  for (int i = 0; i < 1000; i++) {
    bool flag = true;
    if (i != 0 && floor(log10(i) + 1) != n) continue;
    for (int j = 0; j < m; j++) {
      string str = to_string(i);
      switch (s[j]) {
        case 1:
          if (str[0] == c[j]) continue;
          break;
        case 2:
          if (str[1] == c[j]) continue;
          break;
        case 3:
          if (str[2] == c[j]) continue;
          break;
      }
      flag = false;
      break;
    }
    if (flag == true) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
