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