#include <bits/stdc++.h>
int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  int s[M], c[M];
  int n[N], a[N];
  int i, j;
  int result = 0;
  for (i = 0; i < M; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  for (j = 0; j < N; j++) {
    n[j] = 0;
    a[j] = 0;
  }
  for (i = 0; i < M; i++) {
    if (a[s[i] - 1] == 0) {
      n[s[i] - 1] = c[i];
      a[s[i] - 1] = 1;
    } else if (a[s[i] - 1] == 1 && n[s[i] - 1] == c[i]) {
    } else {
      result = -1;
    }
  }
  for (j = 0; j < N; j++) {
    if (a[j] == 0 && j != 0) {
      n[j] == 0;
    } else if (a[0] == 1 && n[0] == 0) {
      result = -1;
    } else if (a[0] == 0) {
      n[0] = 1;
    }
  }
  if (result != -1) {
    for (j = 0; j < N - 1; j++) {
      printf("%d", n[j]);
    }
    printf("%d\n", n[N - 1]);
  } else {
    printf("-1\n");
  }
  return 0;
}
