#include <bits/stdc++.h>
using namespace std;
map<long long, long long> h;
int main() {
  long long a[10], b, c, x[10], y[10], n, m, f = 1;
  memset(a, '\0', sizeof(a));
  scanf("%lld%lld", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld", &x[i], &y[i]);
    if (h[x[i]] != y[i] && h[x[i]] != 0 || x[i] == 1 && y[i] == 0) {
      f = 0;
    } else {
      h[x[i]] = y[i];
    }
  }
  if (n == 1 && m == 0 || f == 0) {
    printf("-1\n");
  } else {
    for (int i = 0; i < m; i++) {
      a[x[i]] = y[i];
    }
    if (a[1] == 0) {
      printf("1");
    } else {
      printf("%lld", a[1]);
    }
    for (int i = 2; i <= n; i++) {
      printf("%lld", a[i]);
    }
    printf("\n");
  }
  return 0;
}
