#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using db = long double;
using ii = pair<ll, ll>;
const ll N = 1e5 + 5, LG = 19, MOD = 998244353;
const ll SQ = 320;
const long double EPS = 1e-7;
set<ll> st[10];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll n, m;
  cin >> n >> m;
  for (ll i = 0, s, c; i < m; i++) {
    cin >> s >> c;
    st[s].insert(c);
  }
  for (ll i = 1; i < n + 1; i++)
    if (st[i].size() > 1) {
      cout << -1 << '\n';
      return 0;
    }
  if (st[1].count(0)) {
    cout << -1 << '\n';
    return 0;
  }
  for (ll i = 1; i < n + 1; i++) {
    if (st[i].empty())
      cout << 0 + (i == 1);
    else
      cout << *st[i].begin();
  }
  return 0;
}
