#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  int upper, lower;
  switch (n) {
    case 1:
      lower = 0;
      upper = 10;
      break;
    case 2:
      lower = 10;
      upper = 100;
      break;
    case 3:
      lower = 100;
      upper = 1000;
      break;
  }
  int ans = -1;
  for (int i = lower; i < upper; i++) {
    bool ok = true;
    string t = to_string(i);
    for (int j = 0; j < n; j++) {
      if (t[s[j]] != c[j]) {
        ok = false;
        break;
      }
    }
    if (ok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
