#include <bits/stdc++.h>
void swap(long long* a, long long* b) {
  long long tmp = *a;
  *a = *b;
  *b = tmp;
}
void YN(int a) {
  if (a == 1) printf("Yes\n");
  if (a == 0) printf("No\n");
}
long long lpow(long long a, long long n) {
  long long ans = pow(a, n) * 10;
  if (ans % 10 < 5) return ans / 10;
  return ans / 10 + 1;
}
long long dup(long long a, long long d) {
  if (a % d == 0)
    return a / d;
  else
    return a / d + 1;
}
long long GCD(long long a, long long b) {
  long long c = 1, tmp = ((a) < (b) ? (b) : (a));
  b = ((a) < (b) ? (a) : (b));
  a = tmp;
  while (c != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
int lcmp(const void* a, const void* b) {
  if (*(long long*)a > *(long long*)b) return 1;
  if (*(long long*)a < *(long long*)b) return -1;
  return 0;
}
int lcmpr(const void* a, const void* b) {
  if (*(long long*)a > *(long long*)b) return -1;
  if (*(long long*)a < *(long long*)b) return 1;
  return 0;
}
int ccmp(const void* a, const void* b) { return *(char*)a - *(char*)b; }
int ccmpr(const void* a, const void* b) { return *(char*)b - *(char*)a; }
int scmp(const void* a, const void* b) { return strcmp((char*)a, (char*)b); }
int scmpr(const void* a, const void* b) { return strcmp((char*)b, (char*)a); }
long long mod(long long a, long long m) {
  if (a < 0)
    return a % m + m;
  else
    return a % m;
}
long long DIV(long long a, long long d) {
  long long m = 1000000007, x = 1, y = 0, k;
  while (m) {
    k = d / m;
    d -= k * m;
    swap(&m, &d);
    x -= k * y;
    swap(&x, &y);
  }
  return mod(a * mod(x, 1000000007), 1000000007);
}
long long FAC(long long a) {
  long long i, ans = 1;
  for (i = 1; i < a + 1; i++) {
    ans *= i;
    if (1000000007 > 0 && ans > 1000000007) ans %= 1000000007;
  }
  return ans;
}
long long POW(long long a, long long n) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) ans = ans * a % 1000000007;
    a = a * a % 1000000007;
    n >>= 1;
  }
  return ans;
}
long long fact[200010], finv[200010], inv[200010];
void comi() {
  long long i;
  fact[0] = fact[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (i = 2; i < 200010; i++) {
    fact[i] = fact[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long com(long long n, long long k) {
  if (n < k || n < 0 || k < 0) return 0;
  return fact[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
int main() {
  long long N, M, i, ans = 0;
  scanf("%lld%lld", &N, &M);
  long long s[M], c[M], k[N + 1];
  for (i = 0; i < M; i++) scanf("%lld%lld", &s[i], &c[i]);
  for (i = 1; i < N + 1; i++) k[i] = -1;
  for (i = 0; i < M; i++) {
    if (k[s[i]] != -1 && k[s[i]] != c[i]) {
      printf("-1");
      return 0;
    } else
      k[s[i]] = c[i];
  }
  if (k[1] == 0) {
    printf("-1");
    return 0;
  }
  for (i = 1; i < N + 1; i++) {
    if (k[i] == -1 && i == 1)
      k[i] = 1;
    else if (k[i] == -1)
      k[i] = 0;
    printf("%lld", k[i]);
  }
  return 0;
}
