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