#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p(m);
  for (int i = 0; i < (m); ++i) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < (1000); ++i) {
    vector<int> x;
    int nn;
    x.push_back(i % 10);
    x.push_back((i / 10) % 10);
    x.push_back((i / 100) % 10);
    if (x[2] != 0) {
      nn = 3;
    } else if (x[1] != 0) {
      nn = 2;
    } else {
      nn = 1;
    }
    if (nn != n) {
      continue;
    }
    bool ok = true;
    reverse(x.begin(), x.end());
    for (int j = 0; j < (m); ++j) {
      if (x[p[j].first - 1] != p[j].second) {
        ok = false;
      }
    }
    if (ok) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
