#include <bits/stdc++.h>
int main() {
  int unused __attribute__((unused));
  int i, j, counter, N, M, num, end, flag = 0;
  int s[3];
  char c[10];
  char a[4];
  unused = scanf("%d %d", &N, &M);
  for (i = 0; i < M; i++) unused = scanf("%d %c", &s[i], &c[i]);
  if (s[i] == 1 && c[i] == 0 && N != 1) {
    printf("%d", -1);
    flag = 1;
  }
  if (s[i] == 1 && c[i] == 0 && N == 1) {
    printf("%d", 0);
    flag = 1;
  }
  end = pow(10, N);
  num = 0;
  while (flag == 0 && num < end) {
    counter = 0;
    if (num < 10)
      j = 1;
    else if (num >= 10 && num < 100)
      j = 2;
    else if (num >= 100)
      j = 3;
    snprintf(a, j + 1, "%d", num);
    for (i = 0; i < M; i++) {
      if (a[s[i] - 1] == c[i]) counter++;
    }
    if (counter == N) {
      printf("%d", num);
      flag = 1;
    }
    num++;
  }
  if (flag == 0) printf("%d", -1);
  return 0;
}
