#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];
  if (D == N) {
    for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
      num[N - s[i]] = c[i];
    }
    for (ll(i) = (0), i_len = (N); (i) < (i_len); ++(i)) cout << num[N - i - 1];
    cout << endl;
  } else
    cout << (-1) << endl;
  return 0;
}
