#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];
  }
  sort((_s).begin(), (_s).end());
  ll D = _s[M - 1];
  vector<ll> num(N, 0);
  bool f = true;
  if (D > N)
    f = false;
  else {
    for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i))
      if (N != 1 && s[i] == 1 && c[i] == 0)
        f = false;
      else {
        for (ll(i) = (0), i_len = (M); (i) < (i_len); ++(i)) {
          if (num[N - s[i]] != 0 && num[N - s[i]] != c[i])
            f = false;
          else {
            num[N - s[i]] = c[i];
          }
        }
        if (N != 1 && num[N - 1] == 0) num[N - 1] = 1;
      }
  }
  if (f) {
    for (ll(i) = (0), i_len = (N); (i) < (i_len); ++(i)) cout << num[N - i - 1];
    cout << endl;
  } else
    cout << (-1) << endl;
  return 0;
}
