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