#include <bits/stdc++.h>
int main(void) {
  int m, n, i, k, j;
  int s[5] = {0}, c[5] = {0};
  int tho = 0, ten = 0, one = 0;
  scanf("%d %d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &s[i], &c[i]);
  }
  for (i = 0; i < m; i++) {
    for (j = 0; j < m; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        printf("-1\n");
        return 0;
      }
    }
  }
  for (i = 0; i < m; i++) {
    if (s[i] == 1) {
      tho = c[i];
    } else if (s[i] == 2) {
      ten = c[i];
    } else if (s[i] == 3) {
      one = c[i];
    }
  }
  for (i = 0; i < m; i++) {
    if (s[i] != 3 && c[i] == 0) {
      printf("-1\n");
      return 0;
    }
  }
  printf("%d%d%d\n", tho, ten, one);
  return 0;
}
