#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, S[1000], C[10], ANS[3];
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  for (int i = 0; i < 1000; i++) {
    bool ok = true;
    string K = to_string(i);
    if (K.length() != N) {
      ok = false;
    }
    for (int j = 0; j < N; j++) {
      if (K[S[j] - 1] != (C[j] + '0')) {
        ok = false;
      }
    }
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
}
