#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(M);
  vector<int> B(M);
  for (int(i) = 0; (i) < (M); i++) {
    cin >> A[i] >> B[i];
  }
  for (int(i) = 0; (i) < (M); i++) {
    for (int j = 1; j + i < M; j++) {
      if (A[i] == A[i + j] && B[i] != B[j]) {
        cout << "-1";
        return 0;
      }
    }
  }
  vector<int> C(N);
  for (int(i) = 0; (i) < (N); i++) {
    C[A[i] - 1] = B[i];
  }
  if (C[N - 1] == 0) {
    cout << "-1";
    return 0;
  }
  for (int(i) = 0; (i) < (N); i++) {
    cout << C[i];
  }
}
