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