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