#include <bits/stdc++.h>
using namespace std;
map<int, bool> M;
vector<long long> get_factor(long long x) {
  vector<long long> res;
  long long len = sqrt(x) + 1;
  for (int i = 2; i <= min(x, len); i++) {
    if (x % i == 0) {
      while (x % i == 0) x /= i;
      if (!M[i]) res.push_back(i);
      M[i] = true;
    }
  }
  if (x != 1) {
    if (!M[x]) res.push_back(x);
    M[x] = true;
  }
  return res;
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
const int maxn = 2e5 + 10;
int a[maxn], b[maxn];
int main() {
  int n;
  cin >> n;
  long long x, y;
  cin >> x >> y;
  if (n == 1) {
    cout << x << endl;
    return 0;
  }
  n--;
  for (int i = 0; i < n; i++) cin >> a[i] >> b[i];
  vector<long long> data = get_factor(x);
  vector<long long> tmp = get_factor(y);
  for (int i = 0; i < tmp.size(); i++) data.push_back(tmp[i]);
  int flag = 0;
  for (int i = 0; i < data.size(); i++) {
    bool mark = true;
    for (int j = 0; j < n; j++) {
      if ((a[j] % data[i] != 0) && (b[j] % data[i] != 0)) {
        mark = false;
        break;
      }
    }
    if (mark) {
      flag = data[i];
      break;
    }
  }
  if (flag != 0)
    cout << flag;
  else
    cout << -1;
}
