#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> s(M), c(M), _s(M);
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    cin >> s[i] >> c[i];
    _s[i] = s[i];
  }
  vector<ll> num(N, 0);
  ll D;
  sort((_s).begin(), (_s).end());
  D = _s[M - 1];
  bool f = true;
  for (ll(i) = (1), i_len = (M); (i) < (i_len); ++(i)) {
    for (ll(j) = (0), j_len = (i); (j) < (j_len); ++(j)) {
      if (s[i] == s[j] && c[i] != c[j]) {
        f = false;
      }
    }
  }
  for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
    if (N != 1 && s[i] == 1 && c[i] == 0) {
      f = false;
    }
  }
  if (f) {
    if (D > N)
      cout << ("-1") << endl;
    else {
      for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
        num[N - s[i]] = c[i];
      }
      if (N != 1 && num[N - 1] == 0) num[N - 1] = 1;
      for (ll i = N - 1; i >= 0; --i) cout << num[i];
      cout << endl;
    }
  } else
    cout << ("-1") << endl;
  return 0;
}
