#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
signed main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < (int)(1000); i++) {
    string x = to_string(i);
    if (x.size() == n) {
      int cnt = 0;
      for (int j = 0; j < (int)(m); j++) {
        if (x[s[j] - 1] == to_string(c[j])[0]) {
          cnt++;
        }
        if (cnt == m) {
          cout << i << endl;
          return 0;
        }
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
