#include <bits/stdc++.h>
long long GCD(long long a, long long b) {
  if (a < b) (a += b, b = a - b, a -= b);
  if (b == 0) return a;
  if (a % b == 0) return b;
  return GCD(b, a % b);
}
long long LCM(long long a, long long b) { return a * b / GCD(a, b); }
double LOG(long long a, long long b) { return log(b) / log(a); }
inline bool BETWEEN(long long x, long long min, long long max) {
  if (min <= x && x <= max)
    return true;
  else
    return false;
}
using namespace std;
signed main() {
  long long N, M, x = 0;
  cin >> N >> M;
  vector<long long> s(M), c(M);
  for (long long i = 0; i < M; i++) cin >> s[i] >> c[i];
  if (N > 1) {
    for (long long i = 0; i < M; i++) {
      if (s[i] == 1 && c[i] == 0) {
        cout << -1;
        return 0;
      }
    }
  }
  for (long long i = 0; i < M; i++) {
    for (long long j = 0; j < M; j++) {
      if (s[i] == s[j] && c[i] != c[j]) {
        cout << -1;
        return 0;
      }
    }
  }
  if (N == 1) {
    for (long long i = 0; i < M; i++) {
      if ((s[i] == 1) && (x == 0)) {
        cout << c[i];
        x++;
      }
      if (x == 0) cout << 0;
    }
  }
  if (N == 2) {
    for (long long i = 0; i < M; i++) {
      if (s[i] == 1 && x == 0) {
        cout << c[i];
        x++;
      }
    }
    if (x == 0) cout << 1;
    x = 0;
    for (long long i = 0; i < M; i++) {
      if (s[i] == 2 && x == 0) {
        cout << c[i];
        x++;
      }
    }
    if (x == 0) cout << 0;
  }
  if (N == 3) {
    for (long long i = 0; i < M; i++) {
      if (s[i] == 1 && x == 0) {
        cout << c[i];
        x++;
      }
    }
    if (x == 0) cout << 1;
    x = 0;
    for (long long i = 0; i < M; i++) {
      if (s[i] == 2 && x == 0) {
        cout << c[i];
        x++;
      }
    }
    if (x == 0) cout << 0;
    x = 0;
    for (long long i = 0; i < M; i++) {
      if (s[i] == 3 && x == 0) {
        cout << c[i];
        x++;
      }
    }
    if (x == 0) cout << 0;
  }
}
