#include <bits/stdc++.h>
using namespace std;
bool is_prime(long long i) {
  for (long long j = 2; j <= sqrt(i); j++) {
    if (i % j == 0) return false;
  }
  return true;
}
set<long long> find_factors(long long x, long long y) {
  set<long long> A;
  while (x % 2 == 0) {
    x = x / 2;
    A.insert(2);
  }
  for (long long i = 3; i <= sqrt(x); i += 2) {
    while (x % i == 0) {
      x = x / i;
      A.insert(i);
    }
  }
  if (x > 2) A.insert(x);
  while (y % 2 == 0) {
    y = y / 2;
    A.insert(2);
  }
  for (long long i = 3; i <= sqrt(y); i += 2) {
    while (y % i == 0) {
      y = y / i;
      A.insert(i);
    }
  }
  if (y > 2) A.insert(y);
  return A;
}
int main() {
  long long n;
  cin >> n;
  vector<pair<long long, long long>> A;
  for (long long i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    A.push_back(make_pair(x, y));
  }
  long long x = A[0].first;
  long long y = A[0].second;
  set<long long> factors = find_factors(x, y);
  bool ans = 0;
  for (auto it : factors) {
    bool flag = true;
    for (long long i = 0; i < n; i++) {
      if (A[i].first % it != 0 && A[i].second % it != 0) {
        flag = false;
        break;
      }
    }
    if (flag) {
      cout << it << endl;
      ans = 1;
      break;
    }
  }
  if (!ans) cout << -1 << endl;
  return 0;
}
