#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> answer(N);
  vector<bool> h(N);
  bool a = false;
  for (int i = 0; i < M; i++) {
    cin >> s.at(i);
    cin >> c.at(i);
    if (h.at(s.at(i) - 1) == true && answer.at(s.at(i) - 1) != c.at(i)) {
      a = true;
    } else if (c.at(i) == 0) {
      a = true;
    }
    answer.at(s.at(i) - 1) = c.at(i);
    h.at(s.at(i) - 1) = true;
  }
  if (a == false) {
    for (int i = 0; i < N; i++) {
      cout << answer.at(i);
    }
    cout << "" << endl;
  } else {
    cout << -1 << endl;
  }
}
