#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  for (long long i = 701; i <= 703; i++) {
    string st = to_string(i);
    if (st.size() == n) {
      bool flag = true;
      for (long long j = 0; j < m; j++) {
        if (st[s[j] - 1] - '0' != (char)(c[j])) {
          flag = false;
        }
      }
      if (flag) {
        cout << st << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
