#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7, MAX = 1e5 + 5;
long long powN(long long a, long long p) {
  if (p == 0) return 1;
  long long z = powN(a, p / 2);
  z = (z * z) % MOD;
  if (p % 2) z = (z * a) % MOD;
  return z;
}
vector<bool> is_prime(MAX + 1, true);
void Sieve() {
  is_prime[0] = is_prime[1] = false;
  int i, j;
  for (i = 2; i * i <= MAX; i++) {
    if (is_prime[i]) {
      for (j = i * i; j <= MAX; j += i) is_prime[j] = false;
    }
  }
}
int main() {
  int n;
  cin >> n;
  long long ans = 1;
  set<long long> S;
  Sieve();
  for (int i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    if (i == 0) {
      long long xx = x;
      for (long long j = 2; j * j <= x; j++) {
        if (!is_prime[j]) continue;
        if (xx % j == 0) {
          S.insert(j);
          while (xx % j == 0) {
            xx /= j;
          }
        }
      }
      if (xx != 1) S.insert(xx);
      long long yy = y;
      for (long long j = 2; j * j <= y; j++) {
        if (!is_prime[j]) continue;
        if (yy % j == 0) {
          S.insert(j);
          while (yy % j == 0) {
            yy /= j;
          }
        }
      }
      if (yy != 1) S.insert(yy);
    } else {
      set<long long> TR;
      for (auto s : S) {
        if (x % s && y % s) {
          TR.insert(s);
        }
      }
      for (auto tr : TR) {
        S.erase(tr);
      }
    }
  }
  if (S.size() == 0)
    cout << -1 << endl;
  else
    cout << *S.begin() << endl;
}
