#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 < m; ++i) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i <= 999; ++i) {
    string str = to_string(i);
    bool ok = true;
    for (int j = 0; j < m; ++j) {
      if (c[j] != str[s[j] - 1] - '0') {
        ok = false;
      }
    }
    if (ok) {
      if (str.size() > n) {
        cout << -1 << endl;
        return 0;
      }
      if (i == 0 && n != 1) {
        cout << -1 << endl;
        return 0;
      }
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
