#include <bits/stdc++.h>
int compare_int(const void *a, const void *b) {
  return *(long long *)a - *(long long *)b;
}
long long factorial(long long n, long long depth) {
  if (n > 1) {
    depth++;
    return factorial(n / 2, depth);
  } else {
    return depth;
  }
}
int min(int a, int b) {
  if (a > b)
    return b;
  else
    return a;
}
int distance(int a, int b) { return abs(a - b) * abs(a - b); }
int main() {
  int a, b, c, d, e, X, Y, r;
  int A[100003] = {};
  int B[100003] = {};
  int C[100003] = {};
  int flg = 0;
  char s[100001] = {};
  char t[100001] = {};
  int i, j, k;
  long long p = 0, q = 0;
  long long min = 100000001;
  int len = 0;
  int l = 0;
  int cnt = 0;
  int num = 0;
  int num1 = 0;
  int num2 = 0;
  long long ans = 0;
  int ans_ac = 0;
  int ans_wa = 0;
  int max = 0;
  long long sum = 0;
  int addr = 0;
  int ptn = 0;
  int tmp = 0;
  double per = 0;
  scanf("%d%d", &a, &b);
  for (i = 0; i < b; i++) {
    scanf("%d%d", &A[i], &B[i]);
    if (A[i] == 1 && B[i] == 0 && b != 1) {
      printf("-1\n");
      return 0;
    }
  }
  for (i = 0; i < b; i++) {
    if (C[A[i] - 1] == 0)
      C[A[i] - 1] = B[i];
    else if (C[A[i] - 1] == B[i])
      ;
    else {
      printf("-1\n");
      return 0;
    }
  }
  for (i = 0; i < a; i++) {
    if (i == 0 && C[0] == 0 && b != 1) C[0] = 1;
    printf("%d", C[i]);
  }
  printf("\n");
  return 0;
}
