#include <bits/stdc++.h>
using namespace std;
long long int pow(long long int a, long long int n) {
  long long int r = 1;
  for (long long int i = 0; i < n; i++) r *= a;
  return r;
}
long long int digitsum(long long int n) {
  long long int r = 0;
  while (n) {
    r += (n % 10);
    n /= 10;
  }
  return r;
}
const long long int inf = 2000000;
long long int i = 0, j = 0, k = 0, T = 0, N = 0, n = 0, tc = 0, t = 0, cnt = 0,
              cnt2 = 0, x = 0, y = 0, r = 0;
int main() {
  long long int n, m;
  cin >> n >> m;
  long long int arr[5 + 1] = {-1, -1, -1, -1, -1, -1};
  long long int a, b;
  while (m--) {
    cin >> a >> b;
    arr[a] = b;
  }
  if (arr[1] == 0) {
    cout << -1;
    return 0;
  }
  if (n >= 1) {
    if (arr[1] == -1)
      cout << "1";
    else
      cout << arr[1];
  }
  if (n >= 2) {
    if (arr[2] == -1)
      cout << "0";
    else
      cout << arr[2];
  }
  if (n >= 3) {
    if (arr[3] == -1)
      cout << "0";
    else
      cout << arr[3];
  }
  return 0;
}
