#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e15;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vll a(n, -1);
  bool ok = true;
  for (int i = (int)(0); i < (int)(m); ++i) {
    ll s, c;
    cin >> s >> c;
    s--;
    if (a[s] == -1 || a[s] == c)
      a[s] = c;
    else
      ok = false;
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 0 && a[0] == -1) {
    cout << -1 << endl;
    return 0;
  }
  if (n > 0 && a[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 0;
  for (int i = (int)(0); i < (int)(n); ++i) {
    if (a[i] == -1) {
      if (i == 0)
        a[i] = 1;
      else
        a[i] = 0;
    }
    ans = ans * 10 + a[i];
  }
  cout << ans << endl;
}
