#include <bits/stdc++.h>
using namespace std;
int main() {
  int ans(-1);
  size_t N, M;
  cin >> N >> M;
  int S[3] = {(10), (10), (10)};
  for (size_t i = 0; i < M; ++i) {
    int si, ci;
    cin >> si >> ci;
    if (S[si - 1] != (10) && S[si - 1] != ci) {
      cout << -1 << endl;
      return 0;
    }
    S[si - 1] = ci;
  }
  if (S[0] == 0 && N > 1) {
    cout << -1 << endl;
    return 0;
  }
  if (S[0] == (10)) {
    cout << 0 << endl;
    return 0;
  }
  if (S[0] == (10)) {
    cout << 1;
  }
  for (size_t i = 1; i < N; ++i) {
    cout << (S[i] == (10) ? 0 : S[i]);
  }
  cout << endl;
  return 0;
}
