#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m = 0;
  cin >> n >> m;
  bool flag = true;
  int s = 0;
  char c;
  string num = "";
  for (int i = 0; i < 1000; i++) {
    flag = true;
    num = to_string(i);
    if (num.size() != n) {
      continue;
    }
    for (int j = 0; j < m; j++) {
      cin >> s >> c;
      if (num[s] != c) {
        flag = false;
        break;
      }
    }
    if (flag == true) {
      break;
    }
  }
  if (flag) {
    for (int i = 0; i < n; i++) {
      cout << num[i];
    }
  } else {
    cout << -1;
  }
  cout << endl;
  return 0;
}
