#include <bits/stdc++.h>
using namespace std;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
  cout << ' ' << A;
  my_dbg(B...);
}
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9 + 7;
const int maxN = 3e5 + 2;
void solve() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> v(n);
  for (int i = 0; i < (int)n; i++) {
    scanf("%d", &v[i].first);
    scanf("%d", &v[i].second);
  }
  set<int> primes;
  for (int i = 2; i * i <= v[0].first; i++) {
    if (v[0].first % i == 0) {
      primes.emplace(i);
      while (v[0].first % i == 0) v[0].first /= i;
    }
  }
  if (v[0].first > 1) primes.emplace(v[0].first);
  for (int i = 2; i * i <= v[0].second; i++) {
    if (v[0].second % i == 0) {
      primes.emplace(i);
      while (v[0].second % i == 0) v[0].second /= i;
    }
  }
  if (v[0].second > 1) primes.emplace(v[0].second);
  map<int, int> ma;
  for (auto p : primes) ma[p]++;
  for (int i = 1; i < (int)n; i++) {
    for (auto p : primes) {
      if ((v[i].first % p == 0) or (v[i].second % p == 0)) {
        ma[p]++;
      }
    }
  }
  int res = -1;
  for (auto it : ma) {
    if (it.second == n) {
      res = it.first;
      break;
    }
  }
  printf("%d\n", (int)(res));
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
