#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int A, B, C, D, E, F, N, M, K, L, X, Y, Z, H, W, sum = 0, num = 0,
                                                             flag = 0;
  string S, T;
  cin >> N >> M;
  vector<pair<long long int, long long int> > P(
      M, pair<long long int, long long int>(0, 0));
  for (long long int i = 0; i < M; i++) cin >> P[i].first >> P[i].second;
  A = pow(10, N);
  B = pow(10, N - 1);
  C = 999999999999999999;
  if (M != 0)
    for (long long int i = B; i < A; i++) {
      S = to_string(i);
      flag = 1;
      for (long long int j = 0; j < N; j++) {
        T = to_string(P[j].second);
        if (S[P[j].first - 1] != T[0]) {
          flag = 0;
          break;
        }
      }
      if (flag) {
        C = i;
        break;
      }
    }
  if (M == 0) C = B;
  if (C != 999999999999999999)
    cout << C << endl;
  else
    cout << -1 << endl;
}
