#include <bits/stdc++.h>
int main(void) {
  int i, j, k;
  int *number;
  int N, M;
  int s, c;
  int flag = 0;
  scanf("%d %d", &N, &M);
  if (M == 0) {
    puts("-1");
    return 0;
  }
  number = new int[N];
  for (i = 0; i < N; i++) number[i] = 0;
  for (i = 0; i < M; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    if (!flag) {
      if ((s > N || s <= 0) || (c < 0 || c >= 10)) {
        flag == 1;
      }
      number[s - 1] = c;
    }
  }
  if (flag || (N != 1 && number[0] == 0)) {
    puts("-1");
  } else {
    for (i = 0; i < N; i++) printf("%d", number[i]);
    puts("");
  }
  return 0;
}
