#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    int keta = s - 1;
    if (N > 1 && keta == 0 && c == 0) {
      cout << "-1";
      return 0;
    } else if (A[keta] == 0 || A[keta] == c) {
      A[keta] = c;
    } else {
      cout << "-1";
      return 0;
    }
  }
  int B = 0;
  if (A[0] == 0 && N > 1)
    B += pow(10, N - 1);
  else {
    for (int i = 0; i < N; i++) {
      B += pow(10, i) * A[N - i - 1];
    }
  }
  cout << B;
  return 0;
}
