#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int main(int argc, const char* argv[]) {
  int N, M;
  cin >> N >> M;
  vector<P> t(M);
  for (int i = 0; i < (M); ++i) {
    cin >> t[i].first >> t[i].second;
  }
  for (int x = 0; x < (1000); ++x) {
    int nx = x;
    vector<int> d(1);
    d[0] = nx % 10;
    nx = nx / 10;
    while (nx) {
      d.push_back(nx % 10);
      nx = nx / 10;
    }
    if (d.size() != N) {
      continue;
    }
    reverse(d.begin(), d.end());
    bool ok = true;
    for (int i = 0; i < (M); ++i) {
      if (d[t[i].first - 1] != t[i].second) {
        ok = false;
      }
    }
    if (ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
