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