#include <bits/stdc++.h>
int main() {
  int a[4] = {0}, b[4] = {0};
  int i, m, n, flag = 0, s, c;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &s, &c);
    if (b[s] == 0) {
      a[s] = c;
      b[s] = 1;
    } else if (a[s] != c) {
      flag = 1;
      break;
    }
  }
  if (a[n] == 0) flag = 1;
  if (n == 1) flag = 0;
  if (flag == 1)
    printf("-1\n");
  else {
    for (i = 1; i <= n; i++) {
      printf("%d", a[i]);
    }
    printf("\n");
  }
  return 0;
}
