#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];
  for (int num = 0; num < 1000; num++) {
    bool flag = true;
    string t = to_string(num);
    for (int i = 0; i < m; i++) {
      if (t[s[i] - 1] != c[i]) flag = false;
    }
    if (flag) {
      if (n > 1 && num == 0) continue;
      cout << num << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
