#include <bits/stdc++.h>
int main() {
  int n, m, i, j;
  int s[5];
  int c[5];
  int data[4] = {0, 0, 0, 0};
  int flag[4] = {1, 1, 1, 1};
  int judge = 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++) {
    if (n != 1 && s[i] == 1 && c[i] == 0) {
      judge = 1;
    }
  }
  for (i = 0; i < m - 1; i++) {
    for (j = i; j < m; j++) {
      if (s[i] == s[j] && c[i] == c[j]) flag[s[i] - 1]++;
    }
  }
  for (i = 0; i < m; i++) {
    if (s[i] > n) judge = 1;
    data[s[i] - 1] = c[i];
    flag[s[i] - 1]--;
  }
  if (judge == 1) printf("-1\n");
  for (i = 0; i < n; i++) {
    printf("%d", data[i]);
  }
  printf("\n");
  return 0;
}
