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