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