#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> ans(N, -1);
  bool judge = true;
  for (int i = 0; i < M; i++) {
    if ((ans.at(s.at(i) - 1) != -1 && ans.at(s.at(i) - 1) != c.at(i)) ||
        (N != 1 && (s.at(i) == 1 && c.at(i) == 0)))
      judge = false;
    else
      ans.at(s.at(i) - 1) = c.at(i);
  }
  if (!judge) {
    cout << -1 << endl;
  } else {
    if (N != 1 && (ans.at(0) == 0 || ans.at(0) == -1)) {
      ans.at(0) = 1;
    }
    for (int i = 1; i < N; i++) {
      if (ans.at(i) == -1) ans.at(i) = 0;
    }
    int answer = 0;
    for (int i = 0; i < N; i++) {
      answer += ans.at(i) * pow(10, N - i - 1);
    }
    cout << answer << endl;
  }
  return 0;
}
