#include <bits/stdc++.h>
int main() {
  int n = 0, m = 0;
  scanf("%d %d", &n, &m);
  int dig1 = -1, dig10 = -1, dig100 = -1;
  int s, c;
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &s, &c);
    if (s == n && (dig1 == -1 || dig1 == c))
      dig1 = c;
    else if (s == n - 1 && (dig10 == -1 || dig10 == c))
      dig10 = c;
    else if (s == n - 2 && (dig100 == -1 || dig100 == c))
      dig100 = c;
    else {
      printf("-1\n");
      return 0;
    }
  }
  if (n == 1) {
    if (dig1 == 0) {
      printf("-1\n");
      return 0;
    }
    if (dig1 == -1) dig1 = 1;
    printf("%d\n", dig1);
  } else if (n == 2) {
    if (dig10 == 0) {
      printf("-1\n");
      return 0;
    }
    if (dig1 == -1) dig1 = 0;
    if (dig10 == -1) dig10 = 1;
    printf("%d%d\n", dig10, dig1);
  } else if (n == 3) {
    if (dig100 == 0) {
      printf("-1\n");
      return 0;
    }
    if (dig1 == -1) dig1 = 0;
    if (dig10 == -1) dig10 = 0;
    if (dig100 == -1) dig100 = 1;
    printf("%d%d%d\n", dig100, dig10, dig1);
  }
  return 0;
}
