#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
const int MOD = 1000000007;
const int MOD_MAX = 200000;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vi>;
using vi3 = vector<vi2>;
using vll = vector<ll>;
using vll2 = vector<vll>;
using vll3 = vector<vll2>;
using vd = vector<double>;
using vd2 = vector<vd>;
using vd3 = vector<vd2>;
using pi = pair<int, int>;
using pll = pair<ll, ll>;
using vpi = vector<pi>;
using vpll = vector<pll>;
using vstr = vector<string>;
using mapsi = map<string, int>;
bool feq(float x, float y) { return abs(x - y) <= eps; }
bool deq(double x, double y) { return abs(x - y) <= eps; }
int ceillog2(ll x) { return int(ceil(log2(x))); }
int floorlog2(ll x) { return int(floor(log2(x))); }
template <class T>
T reversed(T container) {
  reverse(container.begin(), container.end());
  return container;
}
template <class T>
T sort(T container) {
  sort(container.begin(), container.end());
  return container;
}
ll gcd(ll m, ll n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}
ll lcm(ll m, ll n) { return m * n / gcd(m, n); }
ll modinv(ll a) {
  ll b = MOD, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= MOD;
  if (u < 0) u += MOD;
  return u;
}
ll modadd(ll a, ll b) { return ((a % MOD) + (b % MOD)) % MOD; }
ll modmult(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll modsub(ll a, ll b) {
  ll c = a % MOD - b % MOD;
  if (c < 0)
    return c + MOD;
  else
    return c;
}
ll moddiv(ll a, ll b) { return (a % MOD * modinv(b % MOD)) % MOD; }
ll modpow(ll a, ll n) {
  ll ret = 1ll;
  while (n > 0) {
    if (n & 1) ret = modmult(ret, a);
    a = modmult(a, a);
    n >>= 1;
  }
  return ret;
}
ll modcomb(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  ll ret = 1;
  if (r > n / 2) r = n - r;
  for (int i = 0; i < (int)r; i++) ret = modmult(ret, n - i);
  for (int i = 0; i < (int)r; i++) ret = moddiv(ret, i + 1);
  return ret;
}
ll modhcomb(ll n, ll r) { return modcomb(n + r - 1, r); }
ll fact_arr[MOD_MAX + 10], finv_arr[MOD_MAX + 10], inv_arr[MOD_MAX + 10];
void modcomb_init() {
  fact_arr[0] = fact_arr[1] = 1;
  finv_arr[0] = finv_arr[1] = 1;
  inv_arr[1] = 1;
  for (int i = 2; i < MOD_MAX + 10; i++) {
    fact_arr[i] = fact_arr[i - 1] * i % MOD;
    inv_arr[i] = MOD - inv_arr[MOD % i] * (MOD / i) % MOD;
    finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % MOD;
  }
}
ll modcomb_fast(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact_arr[n] * (finv_arr[r] * finv_arr[n - r] % MOD) % MOD;
}
ll modhcomb_fast(ll n, ll r) { return modcomb_fast(n + r - 1, r); }
ll fact_arr2[MOD_MAX + 10], finv_arr2[MOD_MAX + 10];
void modcomb_init2() {
  fact_arr2[0] = 1;
  for (int i = 0; i < (int)MOD_MAX + 10; i++)
    fact_arr2[i + 1] = (i + 1) * fact_arr2[i] % MOD;
  for (int i = 0; i < (int)MOD_MAX + 10; i++)
    finv_arr2[i] = modpow(fact_arr2[i], MOD - 2);
}
ll modcomb_fast2(ll n, ll r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact_arr2[n] * finv_arr2[r] % MOD * finv_arr2[n - r] % MOD;
}
ll modhcomb_fast2(ll n, ll r) { return modcomb_fast2(n + r - 1, r); }
int main() {
  int n, m;
  cin >> n >> m;
  int n1 = -1, n2 = -1, n3 = -1;
  int flag = 0;
  for (int i = 0; i < (int)m; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1) {
      if (n1 == c || n1 == -1)
        n1 = c;
      else
        flag = 1;
    }
    if (s == 2) {
      if (n2 == c || n2 == -1)
        n2 = c;
      else
        flag = 1;
    }
    if (s == 3) {
      if (n3 == c || n3 == -1)
        n3 = c;
      else
        flag = 1;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 3) {
    if (n1 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n1 == -1) n1 = 1;
    if (n2 == -1) n2 = 0;
    if (n3 == -1) n3 = 0;
    cout << n1 * 100 + n2 * 10 + n3 << endl;
  } else if (n == 2) {
    if (n2 == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (n2 == -1) n2 = 1;
    if (n3 == -1) n3 = 0;
    cout << n2 * 10 + n3 << endl;
  } else {
    if (n3 == -1) n3 = 0;
    cout << n3 << endl;
  }
}
