#include <bits/stdc++.h>
int compare(const void *a, const void *b) {
  if (*(int *)a > *(int *)b) return 1;
  return -1;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n < m) {
    printf("-1");
    return 0;
  }
  int s[m], c[m];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s[i], &c[i]);
    if (n > 1 && s[i] == 1 && c[i] == 0) {
      printf("-1");
      return 0;
    }
  }
  for (int i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0)
      continue;
    else {
      break;
    }
    if (i == m - 1) printf("0");
    return 0;
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    char d[4] = {'\n'};
    sprintf(d, "%d", i);
    for (int j = 0; j < m; j++) {
      if (d[s[j] - 1] - '0' != c[j]) break;
      if (j == m - 1) {
        printf("%d", i);
        return 0;
      }
    }
  }
  printf("-1");
  return 0;
}
