#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;
  map<ll, ll> a;
  for (ll i = 0; i < (ll)(m); i++) {
    ll s, c;
    cin >> s >> c;
    if (a[s] != 0 && a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (ll i = 0; i < (ll)(n); i++) {
    if (i == 0) {
      if (a[i + 1] == 0) {
        cout << 1;
        continue;
      }
    }
    cout << a[i + 1];
  }
  return 0;
}
