#include <bits/stdc++.h>
int get_str(char *str, int size) {
  if (!fgets(str, size, stdin)) return -1;
  return 0;
}
int get_int2(int *a1, int *a2) {
  char line[20];
  if (!fgets(line, 20, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
  return 0;
}
int main(void) {
  int n, queries;
  static char map[3];
  int i;
  memset(map, -1, 3);
  get_int2(&n, &queries);
  int flag = 1;
  for (i = 0; i < queries; i++) {
    int pos, digit;
    get_int2(&pos, &digit);
    pos--;
    if (map[pos] != -1 && map[pos] != digit) {
      flag = 0;
    }
    map[pos] = digit;
  }
  if (map[0] == 0) {
    if (n > 1) flag = 0;
  }
  map[0] = (map[1] == -1) ? 1 : map[0];
  map[1] = (map[1] == -1) ? 0 : map[1];
  map[2] = (map[2] == -1) ? 0 : map[2];
  int ans = -1;
  if (flag) {
    int guess = 0;
    int d = 1;
    for (i = n - 1; i >= 0; i--) {
      guess += map[i] * d;
      d *= 10;
    }
    ans = guess;
  }
  printf("%d\n", ans);
  return 0;
}
