#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
ll gcd(ll a, ll b) {
  if (b > a) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll rep_jijo(ll n, ll x) {
  if (x == 0) return 1;
  if (x % 2 == 0) {
    ll t = rep_jijo(n, x / 2);
    return t * t % 1000000007;
  }
  return n * rep_jijo(n, x - 1) % 1000000007;
}
ll c2(ll n) { return n * (n - 1) / 2; }
int main() {
  ll n, m, z, s, c;
  cin >> n >> m;
  ll ans = -1;
  z = rep_jijo(10, n);
  map<ll, ll> con;
  for (ll i = 0; i < (ll)(m); i++) {
    cin >> s >> c;
    con[s] = c;
  }
  for (ll j = z - 1; j >= 0; j--) {
    ll cnt = 0, mm = 0;
    for (auto p : con) {
      auto k = p.first;
      auto v = p.second;
      if (k == 1 && j / 100 == v) {
        cnt++;
      } else if (k == 2 && j % 100 - j % 10 == v) {
        cnt++;
      } else if (k == 3 && j % 10 == v) {
        cnt++;
      }
      mm++;
    }
    if (cnt == mm) ans = j;
  }
  cout << ans << endl;
}
