#include <bits/stdc++.h>
using namespace std;
const int mod = 10;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  int r = 1;
  while (r) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long quick(long long a, long long b) {
  long long sum = 1;
  a = a % mod;
  while (b) {
    if (b % 2 == 1) sum = (sum * a) % mod;
    b >>= 1;
    a = (a * a) % mod;
  }
  return sum;
}
const int maxn = 1e6 * 2;
set<int> st;
int k = 0;
void fun(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      st.insert(i);
      while (x % i == 0) x /= i;
    }
  }
  if (x != 1) st.insert(x);
}
long long a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) scanf("%lld %lld", &a[i], &b[i]);
  if (n == 1)
    cout << a[0] << endl;
  else {
    fun(a[0]);
    fun(b[0]);
    long long ans = 0;
    bool flag = false;
    for (set<int>::iterator i = st.begin(); i != st.end(); i++) {
      for (int j = 1; j < n; j++) {
        if ((a[j] % (*i) == 0) || (b[j] % (*i) == 0)) {
          ++ans;
        } else {
          ans = 0;
          break;
        }
        if (ans == n - 1) {
          cout << *i << endl;
          flag = true;
          return 0;
        }
      }
    }
    if (!flag) cout << -1 << endl;
  }
}
