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