#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, ans, flg;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (ans = 0; ans < 999; ++ans) {
    string sans = to_string(ans);
    flg = 0;
    for (int i = 0; i < (int)(m); i++) {
      if (n == sans.size()) {
        if (sans[s[i] - 1] != c[i]) {
          ++flg;
          break;
        }
      } else
        ++flg;
    }
    if (flg == 0) break;
  }
  if (flg != 0) ans = -1;
  std::cout << ans << endl;
}
