#include <bits/stdc++.h>
using ll = long long;
using namespace std;
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
long long N, M;
long long S[10];
long long C[10];
signed main() {
  cin >> N >> M;
  for (long long(i) = 0; (i) < (M); (i)++) {
    cin >> S[i] >> C[i];
  }
  long long start = pow(10, N - 1);
  long long end = pow(10, N);
  for (long long i = start; i < end; i++) {
    bool is_good = true;
    for (long long j = 0; j < M; j++) {
      if (S[j] == 3 && (i % 10 != C[j])) is_good = false;
      if (S[j] == 2 && ((i / 10 % 10) != C[j])) is_good = false;
      if (S[j] == 1 && ((i / 100 % 10) != C[j])) is_good = false;
    }
    if (is_good) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
