#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T1, typename T2>
bool relax(T1& a, T2 b) {
  if (a > b) return 1 * (a = b);
  return 0;
}
template <typename T1, typename T2>
bool strain(T1& a, T2 b) {
  if (a < b) return 1 * (a = b);
  return 0;
}
vector<ll> get_mul(ll x) {
  ll d = 2;
  vector<ll> res;
  while (d * d <= x) {
    if (x % d == 0) res.emplace_back(d);
    while (x % d == 0) x /= d;
    ++d;
  }
  if (x > 1) res.emplace_back(x);
  return res;
}
void ans(ll x) {
  cout << x << '\n';
  exit(0);
}
void solve() {
  int n;
  cin >> n;
  vector<pair<ll, ll>> a(n);
  auto check = [&](ll prime) -> bool {
    for (int i = 0; i < n; ++i) {
      if (!(a[i].first % prime == 0 || a[i].second % prime == 0)) return 0;
    }
    return 1;
  };
  for (int i = 0; i < n; ++i) {
    cin >> a[i].first >> a[i].second;
  }
  for (const ll& mul : get_mul(a[0].first))
    if (check(mul)) ans(mul);
  for (const ll& mul : get_mul(a[0].second))
    if (check(mul)) ans(mul);
  cout << "-1\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t = 1;
  while (t--) solve();
  return 0;
}
