#include <bits/stdc++.h>
int main(void) {
  int N, M;
  scanf("%d %d", &N, &M);
  int* s;
  int* c;
  char* a;
  s = (int*)calloc(sizeof(int), M);
  c = (int*)calloc(sizeof(int), M);
  a = (char*)calloc(sizeof(char), N);
  for (int i = 0; i < M; ++i) {
    scanf("%d %d", &s[i], &c[i]);
  }
  for (int i = 0; i < M; ++i) {
    if (a[s[i] - 1] == '\0') {
      a[s[i] - 1] = '0' + c[i];
      continue;
    }
    if (a[s[i] - 1] > '0' + c[i]) {
      a[s[i] - 1] = '0' + c[i];
    }
  }
  for (int i = 1; i < 3; ++i) {
    if (a[i - 1] != '\0' && a[i] == '\0') {
      a[i] = '0';
    }
  }
  switch (N) {
    case 3: {
      if (a[0] == '\0') {
        puts("-1");
      } else if (a[0] == '0') {
        puts("-1");
      } else {
        printf("%s\n", a);
      }
      break;
    }
    case 2: {
      if (a[1] == '\0' || a[0] != '\0') {
        puts("-1");
      } else if (a[1] == '0') {
        puts("-1");
      } else {
        printf("%s\n", a);
      }
      break;
    }
    case 1: {
      if (a[2] == '\0' || a[1] != '\0' || a[0] != '\0') {
        puts("-1");
      } else if (a[2] == '0') {
        puts("-1");
      } else {
        printf("%s\n", a);
      }
    }
  }
  free(s);
  free(c);
  free(a);
  return 0;
}
