#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  int c[m];
  int ans = -1;
  string snum;
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int j = 1000; j >= 0; j--) {
    bool ok = true;
    if (snum.size() != n) ok = false;
    snum = to_string(j);
    for (int t = 0; t < m; t++) {
      if (snum[s[t] - 1] != (char)('0' + c[t])) ok = false;
    }
    if (ok) ans = j;
  }
  cout << ans << endl;
  return 0;
}
