#include <bits/stdc++.h>
using namespace std;
const int inf = 2147483647, dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1};
const int N = 100005, M = 1000005, K = 200005, mod = 1000000007;
const long long llinf = 9223372036854775807ll;
int n, m, s[10], c[10], x[10];
bool ok;
int main() {
  cin >> n >> m;
  ok = true;
  for (int i = 1; i <= 3; i++) x[i] = -1;
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
    if (x[s[i]] == -1)
      x[s[i]] = c[i];
    else {
      if (x[s[i]] != c[i]) ok = false;
    }
  }
  if (x[1] == 0) {
    cout << -1;
    return 0;
  }
  if (!ok) {
    cout << -1;
    return 0;
  }
  if (x[1] != -1)
    cout << x[1];
  else {
    if (n > 1)
      cout << 1;
    else
      cout << 0;
  }
  if (n > 1) {
    if (x[2] != -1)
      cout << x[2];
    else
      cout << 0;
  }
  if (n > 2) {
    if (x[3] != -1)
      cout << x[3];
    else
      cout << 0;
  }
  return 0;
}
