#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (s.at(i) == 1 && c.at(i) == '0' && n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      if (i != j && s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int nm = 0;
  for (int i = 0; i <= pow(10, n); i++) {
    string st = to_string(i);
    bool fct = true;
    for (int j = 0; j < m; j++) {
      if (s.at(j) - 1 <= st.size() - 1) {
        if (c.at(j) != st.at(s.at(j) - 1)) fct = false;
      } else
        fct = false;
    }
    if (fct) {
      nm = i;
      break;
    }
  }
  cout << nm << endl;
}
