#include <bits/stdc++.h>
using namespace std;
int N;
int a[200005][2];
bool ok(int x) {
  for (int i = 1; i <= N; i++)
    if (a[i][0] % x && a[i][1] % x) return 0;
  return 1;
}
int solve(int x) {
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) {
      if (ok(i)) return i;
      while (x % i == 0) x /= i;
    }
  return ok(x) && x > 1 ? x : -1;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> a[i][0] >> a[i][1];
  cout << max(solve(a[1][0]), solve(a[1][1]));
  return 0;
}
