#include <bits/stdc++.h>
int main(void) {
  int n, m;
  int s;
  int c;
  scanf("%d %d", &n, &m);
  int p = 0;
  int fal = 0;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s, &c);
    if (s == 1 && c == 0) {
      fal++;
      break;
    } else if ((int)(p / pow(10, n - s)) % 10 != 0 &&
               (int)(p / pow(10, n - s)) % 10 != c) {
      fal++;
      break;
    } else if ((int)(p / pow(10, n - s)) % 10 == c) {
    } else {
      p += pow(10, n - s) * c;
    }
  }
  if (p < pow(10, n - 1)) {
    p += pow(10, n - 1);
  }
  if (fal) {
    printf("-1\n");
  } else {
    printf("%d\n", p);
  }
  return 0;
}
