#include <bits/stdc++.h>
int A[3];
bool B[3];
int main() {
  int N, M;
  std::cin >> N >> M;
  bool ok = true;
  while (static_cast<bool>(M--)) {
    int s, c;
    std::cin >> s >> c;
    s += 2 - N;
    if (B[s] && A[s] != c) {
      ok = false;
      break;
    }
    A[s] = c;
    B[s] = true;
  }
  int num = A[0] * 100 + A[1] * 10 + A[2];
  int digit = 1;
  if (A[0] != 0)
    digit = 3;
  else if (A[1] != 0)
    digit = 2;
  if (digit != N) ok = false;
  if (!ok) num = -1;
  std::cout << num << std::endl;
  return 0;
}
