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