#include <bits/stdc++.h>
int main() {
  int n, x;
  scanf("%d %d", &n, &x);
  int j[n];
  for (int i = 0; i < n; i++) j[i] = 0;
  int a, b;
  for (int i = 0; i < x; i++) {
    scanf("%d %d", &a, &b);
    if (b < j[a - 1]) j[a - 1] = b;
  }
  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;
}
