#include <bits/stdc++.h>
using namespace std;
void solve(void) {
  int n, m;
  cin >> n >> m;
  vector<int> s(10, 0);
  vector<char> c(10, 0);
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  bool flag = false;
  int res = 1000;
  for (int d = 1; d < 1000; ++d) {
    string t = to_string(d);
    if ((int)t.size() != n) continue;
    int count = 0;
    for (int i = 0; i < m; ++i) {
      if (t[s[i] - 1] != c[i]) continue;
      count++;
    }
    if (count == m) {
      flag = true;
      res = min(res, d);
      break;
    }
  }
  cout << ((flag) ? res : -1) << endl;
}
int main(void) {
  solve();
  return 0;
}
