#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
ll power(ll x, ll y) {
  ll ret = 1;
  while (y-- > 0) ret *= x;
  return ret;
}
ll gcd(ll a, ll b) {
  assert(a >= 0);
  assert(b >= 0);
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll& x, ll& y) {
  x = 1;
  y = 0;
  assert(a >= 0);
  assert(b >= 0);
  if (b == 0) return a;
  ll X, Y;
  auto d = extgcd(b, a % b, X, Y);
  x = Y;
  y = X - (a / b) * Y;
  return d;
}
int run(istream& in, ostream& out) {
  ll N, M;
  in >> N >> M;
  vector<ll> s(M), c(M);
  vector<ll> v(N, -1);
  bool valid = true;
  for (ll i = 0; i < (M); ++i) {
    in >> s[i] >> c[i];
    auto ss = s[i] - 1;
    auto cc = c[i];
    if (v[ss] == -1 || v[ss] == cc)
      v[ss] = cc;
    else {
      valid = false;
      break;
    }
    if (ss == 0 && cc == 0) {
      valid = false;
      break;
    }
  }
  if (!valid) {
    out << -1 << endl;
    return 0;
  }
  ll ans = 0;
  for (ll i = 0; i < (v.size()); ++i) {
    auto& x = v[i];
    if (x == -1) {
      if (i == 0)
        x = 1;
      else
        x = 0;
    }
  }
  reverse(v.begin(), v.end());
  for (ll i = 0; i < (v.size()); ++i) {
    ans += v[i] * (power(10, i));
  }
  out << ans << endl;
  return 0;
}
int main() { return run(cin, cout); }
