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