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