#include <bits/stdc++.h>
int main(void) {
  int n, m, i, s, c, digit[3] = {-2, -2, -2};
  scanf("%d %d", &n, &m);
  for (i = m; i > 0; i--) {
    scanf("%d %d", &s, &c);
    if (digit[2 - n + s] == -2) {
      digit[2 - n + s] = c;
    } else if (digit[2 - n + s] != c) {
      printf("-1\n");
      exit(0);
    }
  }
  if (digit[3 - n] == 0) {
    printf("-1\n");
    exit(0);
  } else if (digit[3 - n] == -2)
    printf("1");
  else
    printf("%d", digit[3 - n]);
  for (i = 4 - n; i < 3; i++) {
    if (digit[i] == -2)
      printf("0");
    else
      printf("%d", digit[i]);
  }
  printf("\n");
  return 0;
}
