#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
bool custom1(pair<int, int> a, pair<int, int> b) { return (a.first < b.first); }
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}
const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; 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) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
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 gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> digit(n, -1);
  bool yes = true;
  for (int(i) = 0; (i) < (m); (i)++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (digit[s] == -1)
      digit[s] = c;
    else if (digit[s] != c)
      yes = false;
  }
  if (!yes) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) {
    cout << digit[0] << endl;
  } else if (n == 2) {
    if (digit[0] == -1)
      digit[0] = 1;
    else if (digit[0] == 0)
      yes = false;
    if (digit[1] == -1) digit[1] = 0;
    if (yes)
      cout << digit[0] << digit[1] << endl;
    else
      cout << -1 << endl;
  } else {
    if (digit[0] == -1)
      digit[0] = 1;
    else if (digit[0] == 0)
      yes = false;
    if (digit[1] == -1) digit[1] = 0;
    if (digit[2] == -1) digit[2] = 0;
    if (yes)
      cout << digit[0] << digit[1] << digit[2] << endl;
    else
      cout << -1 << endl;
  }
}
