#include <bits/stdc++.h>
#pragma warning(disable : 4996)
int main(void) {
  int* list;
  int input[2];
  int n, m, res = 1;
  scanf("%d%d", &n, &m);
  list = (int*)malloc(sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    list[i] = 0;
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &input[0], &input[1]);
    if (list[input[0] - 1] != 0 && list[input[0] - 1] != input[1]) {
      res = 0;
    }
    list[input[0] - 1] = input[1];
  }
  if (n != 1 && list[0] == 0) {
    list[0] = 1;
    res = 1;
  }
  for (int i = 0; i < n; i++) {
    if (list[i] == 0) res += 1;
  }
  if (n == 1 && list[0] == 0) {
    res = 1;
  }
  if (res > 1) {
    printf("%d", 0);
  } else if (res != 0) {
    for (int i = 0; i < n; i++) {
      printf("%d", list[i]);
    }
  } else {
    printf("%d", -1);
  }
  free(list);
  list = NULL;
  return 0;
}
