#include <bits/stdc++.h>
using namespace std;
int A[3];
int main() {
  int N, M, s, c;
  bool flg = true;
  for (int i = 0; i < 3; i++) A[i] = -1;
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (A[s - 1] >= 0 && A[s - 1] != c || s - 1 < 3 - N) {
      flg = false;
    }
    A[s - 1] = c;
  }
  for (int i = 0; i < N; i++) {
    if (A[2 - i] == -1) A[2 - i] = 0;
  }
  if (N != 1 && A[2 - N + 1] == 0) flg = false;
  if (flg) {
    for (int i = 0; i < 3; i++) {
      if (A[i] >= 0) cout << A[i];
    }
  } else
    cout << -1;
  cout << endl;
  return 0;
}
