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