#include <bits/stdc++.h>
using namespace std;
int 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)(pow(10, n)); i++) {
    string ans = to_string(i);
    bool ok = true;
    for (int j = 0; j < (int)(m); j++) {
      if (ans[s[j] - 1] != '0' + c[j]) {
        ok = false;
      }
    }
    if (ok) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
}
