#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
void divisors(long long n) {
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
      }
      v.push_back(i);
    }
  }
  if (n > 1) v.push_back(n);
}
int main() {
  int n;
  long long a, b;
  cin >> n;
  cin >> a >> b;
  divisors(a);
  divisors(b);
  for (int i = 0; i < n - 1; i++) {
    vector<long long> p;
    cin >> a >> b;
    for (auto it : v) {
      if (a % it == 0 || b % it == 0) {
        p.push_back(it);
      }
    }
    v = p;
  }
  if (v.empty()) {
    cout << -1 << endl;
  } else {
    cout << v[0] << endl;
  }
  return 0;
}
