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