#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m, 0);
  vector<int> c(m, 0);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; i++) {
    vector<int> ans(1, i % 10);
    int ni = i / 10;
    while (ni > 0) {
      ans.push_back(ni);
      ni = ni / 10;
    }
    if (ans.size() != n) continue;
    reverse(ans.begin(), ans.end());
    bool valid_ok = true;
    for (int i = 0; i < m; i++) {
      if (ans[s[i] - 1] != c[i]) {
        valid_ok = false;
      }
    }
    if (valid_ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
