#include <bits/stdc++.h>
template <class T>
inline T chmax(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class T>
inline T chmin(T& a, const T b) {
  return a = (a > b) ? b : a;
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = acos(-1);
using namespace std;
signed main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> vec(N, INF);
  ll s, c;
  ll flag = 1;
  for (ll i = 0; i < ll(M); ++i) {
    cin >> s >> c;
    s--;
    if (vec[s] == INF)
      vec[s] = c;
    else if (vec[s] != c) {
      flag = 0;
    }
  }
  for (ll i = 0; i < ll(N); ++i) {
    if (vec[i] == INF) {
      if (i == 0)
        vec[i] = 1;
      else
        vec[i] = 0;
    }
  }
  if (vec[0] == 0) flag = 0;
  if (flag) {
    cout << vec[0] << vec[1] << vec[2] << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
