#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> num(N, 0);
  vector<bool> exist(N, false);
  bool ok = false;
  for (int i = 0; i < (int)(M); ++i) {
    int a, b;
    cin >> a >> b;
    if (exist.at(a - 1) && num.at(a - 1) != b) {
      ok = true;
      break;
    } else {
      num.at(a - 1) = b;
      exist.at(a - 1) = true;
    }
  }
  int ans = 0;
  for (int i = 0; i < (int)(N); ++i) {
    ans += pow(10, N - 1 - i) * num.at(i);
  }
  if (ans < pow(10, N)) ans += pow(10, N);
  bool mendou = false;
  if (N >= 2 && num.at(0) == 0 && exist.at(0)) mendou = true;
  if (ok || mendou)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
