#include <bits/stdc++.h>
using namespace std;
int main(void) {
  char num[5];
  num[0] = num[1] = num[2] = '-';
  int N, M;
  scanf("%d%d", &N, &M);
  num[N] = 0;
  int si, ci;
  while (M--) {
    scanf("%d%d", &si, &ci);
    if (num[si - 1] == '-' || num[si - 1] == '0' + ci) {
      num[si - 1] = '0' + ci;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  if (num[0] == '0' && (num[1] != 0 || N > 1)) {
    printf("-1\n");
    return 0;
  } else {
    for (int j = 0; j < N; j++) {
      if (num[j] == '-') num[j] = '0';
    }
  }
  printf("%s\n", num);
  return 0;
}
