#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M), K(N);
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  for (int i = pow(10, N - 1); i < pow(10, N); i++) {
    for (int j = 0; j < N; j++) {
      int denom = pow(10, j);
      K[j] = (i / denom) % 10;
    }
    reverse(K.begin(), K.end());
    bool b = true;
    for (int j = 0; j < M; j++) {
      if (i == 702) {
      }
      if (K[S[j] - 1] != C[j]) {
        b = false;
      }
    }
    if (b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
