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