#include <bits/stdc++.h>
using namespace std;
set<long long int> s;
map<long long int, long long int> cnt;
void factorise(long long int n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      s.insert(i);
      while (n % i == 0) {
        n = n / i;
      }
    }
  }
  if (n > 1) s.insert(n);
}
int main() {
  ios_base::sync_with_stdio(false);
  long long int n, i, ans = -1;
  cin >> n;
  vector<pair<long long int, long long int> > a;
  for (i = 0; i < n; i++) {
    long long int x, y;
    cin >> x >> y;
    a.push_back(make_pair(x, y));
  }
  if (n == 1) {
    cout << a[0].first << "\n";
    return 0;
  }
  factorise(a[0].first);
  factorise(a[0].second);
  for (i = 1; i < n; i++) {
    for (auto it : s) {
      if (a[i].first % it == 0)
        cnt[it]++;
      else if (a[i].second % it == 0)
        cnt[it]++;
    }
  }
  for (auto it : cnt) {
    if (it.second == n - 1) {
      ans = it.first;
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}
