#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  map<ll, ll> S;
  for (ll i = 0; i < M; i++) {
    ll s, c;
    cin >> s >> c;
    if (S.count(s)) {
      if (S.at(s) != c) {
        cout << -1 << endl;
        return 0;
      }
    }
    S[s] = c;
  }
  vector<ll> vec(N);
  for (auto x : S) {
    vec[x.first - 1] = x.second;
  }
  if (vec[0] == 0 && vec.size() > 1) {
    cout << -1 << endl;
    return 0;
  }
  for (ll x : vec) {
    cout << x;
  }
  cout << endl;
}
