#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, ans = -1, bu;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (long long i = (pow(10, (n - 1))); i <= (pow(10, n) - 1); i++) {
    vector<bool> o(m, false);
    for (long long k = 0; k < (long long)(m); k++) {
      if (s[k] == 1) {
        bu = i / 100;
      } else if (s[k] == 2) {
        bu = (i % 100) / 10;
      } else {
        bu = (i % 100) % 10;
      }
      if (bu == c[k]) {
        o[k] = true;
      }
    }
    for (long long k = 0; k < (long long)(m); k++) {
      if (!o[k]) {
        break;
      }
      if (k == m - 1 && o[k]) {
        ans = i;
      }
    }
    if (ans != -1) {
      break;
    }
  }
  cout << ans << endl;
}
signed main() {
  solve();
  return 0;
}
