#include <bits/stdc++.h>
int main(void) {
  int N, M;
  int a[M][2], b[N];
  int i, j;
  int x, y;
  scanf("%d", &N);
  scanf("%d", &M);
  for (i = 0; i < M; i++) {
    for (j = 0; j < 2; j++) {
      scanf("%d", &a[i][j]);
    }
  }
  b[N - 1] = 1;
  for (i = 0; i < N - 1; i++) {
    b[i] = 0;
  }
  for (i = 0; i < M; i++) {
    for (j = 1; j <= N; j++) {
      if (a[i][0] == j) b[N - j] = a[i][1];
    }
  }
  x = 0;
  for (i = 0; i < N; i++) {
    x += b[i] * pow(10.0, (double)i);
  }
  for (i = 0; i < M; i++) {
    if (N != 1) {
      if (a[i][0] == 1 && a[i][1] == 0) {
        x = -1;
      }
    }
    for (j = i + 1; j < M; j++) {
      if (a[i][0] == a[j][0] && a[i][1] != a[j][1]) {
        x = -1;
      }
    }
  }
  if (N == 1) {
    if (M != 0) {
      x = a[0][1];
    } else
      x = 0;
  }
  printf("%d", x);
  return 0;
}
