#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;
int main(void) {
  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] >> c[i];
    s[i]--;
  }
  int ans = -1;
  for (int j = 0; j < 1500; j++) {
    int x = 0;
    string t = to_string(j);
    for (int i = 0; i < (int)(m); i++) {
      string y = to_string(c[i]);
      if (t.size() == n && t[s[i]] == y[0]) {
        x++;
      }
    }
    if (x == m) {
      ans = j;
      break;
    } else
      x = 0;
  }
  cout << ans << endl;
}
