#include <bits/stdc++.h>
using namespace std;
vector<pair<string, pair<int, int> > > vec;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M), c(M), res(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  bool flg = true;
  for (int i = 0; i < M; i++) {
    if (s[i] > N) {
      cout << "-1" << endl;
      return 0;
    }
    if (res[s[i]] != -1 && res[s[i]] != c[i]) {
      cout << "-1" << endl;
      return 0;
    }
    if (N > 1 && s[i] == 0 && c[i] == 0) {
      cout << "-1" << endl;
      return 0;
    }
    res[s[i]] = c[i];
  }
  bool flg2 = false;
  long long cnt = 0;
  for (int i = 0; i < N; i++) {
    if (res[i] == -1) {
      res[i] = 0;
      if (!flg2) cnt++;
    } else {
      flg2 = true;
    }
  }
  if (flg) {
    for (long long i = cnt; i < N; i++) {
      cout << res[i];
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
}
