#include <bits/stdc++.h>
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  int j[n], p[n];
  for (int i = 0; i < n; i++) {
    j[i] = 0;
    p[i] = 0;
  }
  int a, b;
  for (int i = 0; i < x; i++) {
    scanf("%d %d", &a, &b);
    if (p[a - 1] == 1 && b < j[a - 1]) j[a - 1] = b;
    if (p[a - 1] == 0) {
      j[a - 1] = b;
      p[a - 1] = 1;
    }
  }
  if (j[0] != 0)
    for (int i = 0; i < n; i++) {
      printf("%d", j[i]);
    }
  else if (n == 1)
    printf("0");
  else
    printf("-1");
  return 0;
}
