#include <bits/stdc++.h>
using namespace std;
const long long infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;
const int MOD = 1000000007;
long long gcd(long long x, long long y) {
  long long r = x % y;
  if (r == 0)
    return y;
  else
    return gcd(y, r);
}
long long lcm(long long x, long long y) { return x * y / gcd(x, y); }
vector<long long> mfactor(long long n) {
  vector<bool> ip(n, true);
  vector<long long> mf(n, -1);
  ip[0] = false;
  ip[1] = false;
  mf[0] = 0;
  mf[1] = 1;
  for (int64_t i = 0; i < n; i++) {
    if (ip[i]) {
      mf[i] = i;
      for (long long j = i * i; j < n; j += i) {
        ip[j] = false;
        if (mf[j] == -1) mf[j] = i;
      }
    }
  }
  return mf;
}
vector<pair<long long, int> > get_prime(long long n,
                                        const vector<long long> &mf) {
  vector<pair<long long, int> > plist;
  while (n != 1) {
    int cnt = 0;
    long long m = mf[n];
    while (mf[n] == m) {
      cnt++;
      n /= m;
    }
    plist.push_back(pair<long long, int>(m, cnt));
  }
  return plist;
}
void COMinit(int m, vector<long long> &fac, vector<long long> &finv) {
  vector<long long> inv(m);
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < m; 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 COM(int n, int k, const vector<long long> &fac,
              const vector<long long> &finv) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
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 powmod(long long x, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
void perm1(int pos, int n, vector<int> &used, vector<int> &perm) {
  if (pos == n) {
    for (auto v : perm) {
      cout << v << ' ';
    }
    cout << endl;
  }
  for (int i = 0; i < n; i++) {
    if (!used[i]) {
      used[i] = true;
      perm[pos] = i;
      perm1(pos + 1, n, used, perm);
      used[i] = false;
    }
  }
  return;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  bool flg = false;
  for (int64_t i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] != -1 && ans[s - 1] != c) flg = true;
    ans[s - 1] = c;
  }
  if (flg) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1 && ans[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (ans[0] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (ans[0] == -1)
    cout << 1;
  else
    cout << ans[0];
  for (int64_t i = 1; i < n; i++) {
    if (ans[i] == -1)
      cout << 0;
    else
      cout << ans[i];
  }
  cout << endl;
}
