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