#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  vector<int> Num(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> S.at(i) >> C.at(i);
    if (Num.at(S.at(i) - 1) != -1 && Num.at(S.at(i) - 1) != C.at(i)) {
      cout << -1 << endl;
      return 0;
    } else {
      Num.at(S.at(i) - 1) = C.at(i);
    }
  }
  if (Num.at(0) == 0 && N != 1) {
    cout << -1 << endl;
    return 0;
  } else {
    for (int i = 0; i < N; i++) {
      if (Num.at(i) >= 0)
        cout << Num.at(i);
      else if (i != 0)
        cout << 0;
      else
        cout << 1;
    }
    cout << endl;
    return 0;
  }
}
