#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> sc(m);
  for (auto& e : sc) {
    cin >> e.first >> e.second;
  }
  int res = -1;
  int d;
  for (int i = 0; i < 1000; i++) {
    d = (i == 0 ? 1 : (int)(log10(i)) + 1);
    if (d != n) continue;
    for (int j = 0; j < m; j++) {
      if ((int)(i / pow(10, n - sc[j].first)) % 10 != sc[j].second) break;
      if (j == m - 1) res = i;
    }
    if (res != -1) break;
  }
  if (n == 1 && m == 0) res = 0;
  cout << res << endl;
  return 0;
}
