#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
bool prime(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return n != 1;
}
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
long long mod_pow(long long n, long long p, long long m) {
  if (p == 0) return 1;
  if (p % 2 == 0) {
    long long t = mod_pow(n, p / 2, m);
    return (t * t) % m;
  }
  return n * mod_pow(n, p - 1, m) % m;
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
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 digit(long long x) {
  long long cnt = 0;
  while (x > 0) {
    cnt += x % 10;
    x /= 10;
  }
  return cnt;
}
long long read() {
  long long tmp;
  cin >> tmp;
  return tmp;
}
long long xor128() {
  static long long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
  long long t = (x xor (x << 11));
  x = y;
  y = z;
  z = w;
  return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<long long, long long> factaring(long long x) {
  map<long long, long long> ans;
  long long now = 2;
  while (now * now <= x) {
    if (x % now == 0) {
      x /= now;
      ans[now]++;
    } else
      now++;
  }
  if (x != 1) ans[x]++;
  return ans;
}
const long long MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; 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 COM(long long n, long long 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 MY_COM(long long n, long long k) {
  long long x = 1, y = 1;
  for (long long i = 0; i < k; i++) {
    y *= i + 1;
    y %= 1000000007;
  }
  for (long long i = n - k + 1; i <= n; i++) {
    x *= i;
    x %= 1000000007;
  }
  return x * modinv(y, 1000000007) % 1000000007;
}
signed main() {
  long long n, m;
  cin >> n >> m;
  long long s[10], c[10];
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  long long ans[10];
  for (long long i = 0; i < n; i++) ans[i] = -1;
  for (long long i = 0; i < m; i++) {
    if (ans[s[i]] == -1)
      ans[s[i]] = c[i];
    else if (ans[s[i]] != c[i]) {
      cout << -1 << endl;
    }
  }
  bool fl = false;
  for (long long i = 0; i < n; i++) {
    if (ans[i] != -1 && ans[i] != 0) fl = true;
  }
  if (!fl && n == 1)
    cout << 0 << endl;
  else if (!fl && n != 1)
    cout << -1 << endl;
  else {
    long long de = false;
    for (long long i = 0; i < n; i++) {
      if (!de && ans[i] == -1)
        cout << 1;
      else if (!de) {
        cout << ans[i];
        de = true;
      } else if (ans[i] == -1)
        cout << 0;
      else
        cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}
