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