#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, e, f, g, n, m, k, l, A[200005], B[200005], fix[200005];
int main() {
  cin >> n >> m;
  fix[1] = -1;
  fix[2] = -1;
  fix[3] = -1;
  for (long long i = 1; i <= m; i++) {
    cin >> A[i] >> B[i];
    if (A[i] > n) a = 1;
    if (fix[A[i]] != -1 && fix[A[i]] != B[i]) a = 1;
    fix[A[i]] = B[i];
  }
  if (m > n || a == 1) {
    cout << -1;
    return 0;
  }
  if (n != 1 && fix[1] == 0) {
    cout << -1;
    return 0;
  }
  if (n == 1) {
    if (fix[1] == -1)
      cout << 0;
    else
      cout << fix[1];
    return 0;
  }
  if (n == 2) {
    if (fix[1] == -1)
      cout << 1;
    else
      cout << fix[1];
    if (fix[2] == -1)
      cout << 0;
    else
      cout << fix[2];
  }
  if (n == 3) {
    if (fix[1] == -1)
      cout << 1;
    else
      cout << fix[1];
    if (fix[2] == -1)
      cout << 0;
    else
      cout << fix[2];
    if (fix[3] == -1)
      cout << 0;
    else
      cout << fix[3];
  }
}
