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