#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  rep(i, m) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  rep(i, 1000) {
    string str = to_string(i);
    if (str.size() != n) continue;
    bool ok = true;
    rep(i, m) {
      if (str[s[i]] != c[i] + '0') {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
