#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
const long long INF = 100000000000010000;
vector<long long> dx = {0, 1, 0, -1, 1, -1, 1, -1, 0};
vector<long long> dy = {1, 0, -1, 0, 1, 1, -1, -1, 0};
void chmin(long long& x, long long y) { x = min(x, y); }
void chmax(long long& x, long long y) { x = max(x, y); }
long long pow_long(long long x, long long y) {
  long long res = 1;
  while (y > 0) {
    if (y % 2 == 1) res *= x;
    x *= x;
    y /= 2;
  }
  return res;
}
void test() { cout << "888888888888888888888888" << endl; }
long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long pow_mod(long long x, long long k) {
  x %= mod;
  long long res = 1;
  while (k > 0) {
    if (k % 2) {
      res *= x;
      res %= mod;
    }
    x *= x;
    x %= mod;
    k /= 2;
  }
  return res;
}
long long div_mod(long long x) { return pow_mod(x, mod - 2); }
const int MAXcomb = 1000010;
long long fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAXcomb; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
long long comb(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * finv[k] % mod * finv[n - k] % mod;
}
long long N;
long long M;
long long second;
long long c;
long long ans[4];
void solve() {
  cin >> N >> M;
  for (long long i = 0; i < (4); i++) ans[i] = -1;
  for (long long i = 0; i < (M); i++) {
    cin >> second >> c;
    if (second > 3 || (ans[second] != -1 && ans[second] != c)) {
      cout << -1 << endl;
      return;
    }
    ans[second] = c;
  }
  if (ans[1] == -1) ans[1] = 1;
  if (ans[2] == -1) ans[2] = 0;
  if (ans[3] == -1) ans[3] = 0;
  for (long long i = 0; i < (3); i++) cout << ans[i + 1];
  cout << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long pair<long long, pair<long long, long long> > = 1;
  for (long long i = 0; i < (pair<long long, pair<long long, long long> >); i++)
    solve();
}
