#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(N, 0);
  vector<int> s(M), c(M);
  map<int, int> m;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (m.count(s.at(i))) {
      if (m.at(s.at(i)) != c.at(i)) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      m[s.at(i)] = c.at(i);
    }
    S.at(s.at(i) - 1) = c.at(i);
  }
  if (S.size() != 1) {
    for (int i = 0; i < N - 1; i++) {
      if (S.at(i) == 0) {
        cout << -1 << endl;
        return 0;
      } else {
        break;
      }
    }
  }
  for (int i = 0; i < S.size(); i++) {
    cout << S.at(i);
    if (i == S.size() - 1) {
      cout << endl;
    }
  }
  return 0;
}
