#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < pow(10, N); i++) {
    vector<int> r(N);
    for (int j = 0; j < N; j++) {
      int s = static_cast<int>(pow(10.0, j));
      r[j] = (i / s) % 10;
    }
    bool toContinue = true;
    for (int j = 0; toContinue && j < M; j++) {
      toContinue = (r[M - s.at(j)] == c.at(j));
    }
    if (toContinue) {
      if (int(log10(i)) == N - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
