#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.at(i).first >> p.at(i).second;
  }
  for (int x = 0; x < 1000; x++) {
    int nx = x / 10;
    vector<int> d(1, x % 10);
    while (nx) {
      d.push_back(nx % 10);
      nx /= 10;
    }
    if (n != d.size()) continue;
    reverse(d.begin(), d.end());
    bool ok = true;
    for (int i = 0; i < m; i++) {
      if (p[i].second != d[p[i].first - 1]) ok = false;
    }
    if (ok) cout << x << endl;
  }
  cout << -1 << endl;
}
