#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a / g * b;
}
ll isPrime(ll n) {
  if (n < 2) {
    return 0;
  }
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
vector<ll> getDivisor(ll n) {
  vector<ll> v;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      v.push_back(i);
      if (i != n / i) {
        v.push_back(n / i);
      }
    }
  }
  sort(v.begin(), v.end());
  return v;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n, m;
  cin >> n >> m;
  vector<ll> ans(n);
  for (ll i = 0; i < (ll)(n); i++) ans[i] = 100;
  vector<ll> s(m), c(m);
  for (ll i = 0; i < (ll)(m); i++) cin >> s[i] >> c[i];
  for (ll i = 0; i < (ll)(m); i++) {
    if (s[i] != 1) continue;
    if (n == 1) continue;
    if (c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (ll i = 0; i < (ll)(m); i++) {
    if (ans[s[i] - 1] != 100 && ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  for (ll i = 0; i < (ll)(n); i++) {
    if (ans[i] == 100) {
      if (i == 0)
        cout << 1;
      else
        cout << 0;
    } else {
      cout << ans[i];
    }
  }
  return 0;
}
