#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int x, long long int y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
long long int lcm(long long int x, long long int y) {
  return x * y / gcd(x, y);
}
long long int modpow(long long int a, long long int n, long long int p) {
  if (n == 0) return 1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  long long int t = modpow(a, n / 2, p);
  return (t * t) % p;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long int fac[510000], finv[510000], inv[510000];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < 510000; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long int COM(long long int n, long long int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
long long int com(long long int n, long long int m) {
  if (n < m || n <= 0 || m < 0) {
    return 0;
  }
  if (m == 0 || n == m) {
    return 1;
  }
  long long int k = 1;
  for (long long int i = 1; i <= m; i++) {
    k *= (n - i + 1);
    k %= 1000000007;
    k *= modinv(i, 1000000007);
    k %= 1000000007;
  }
  return k;
}
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int di[n + 1];
  for (long long int i = 1; i <= (long long int)(n); i++) {
    di[i] = -1;
  }
  for (long long int i = 1; i <= (long long int)(m); i++) {
    long long int s, c;
    cin >> s >> c;
    if (di[s] != -1 && di[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    di[s] = c;
  }
  for (long long int i = 1; i <= (long long int)(n); i++) {
    if (i == 1 && di[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (i == 1 && di[i] == -1) {
      di[i] = 1;
      continue;
    }
    if (di[i] == -1) {
      di[i] = 0;
      continue;
    }
  }
  long long int ans = 0;
  for (long long int i = 1; i <= (long long int)(n); i++) {
    ans += di[i] * modpow(10, n - i, 100000000000);
  }
  cout << ans << endl;
  return 0;
}
