#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n, m;
  cin >> n >> m;
  vector<bool> b(n, true);
  vector<ll> ans(n, 0);
  ;
  for (ll j = 0; j < (ll)m; j++) {
    ll s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (b[s - 1]) {
      b[s - 1] = false;
      ans[s - 1] = c;
    } else if (!b[s - 1] && ans[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  };
  for (ll i = 0; i < (ll)n; i++) cout << ans[i];
  cout << endl;
}
