#include <bits/stdc++.h>
long long gcd(long long x, long long y) { return x % y ? gcd(y, x % y) : y; }
inline long long solve(long long n) {
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) return i;
  return n;
}
int main() {
  long long n, a, b;
  scanf("%lld", &n);
  scanf("%lld%lld", &a, &b);
  long long ans = a * b / gcd(a, b);
  n -= 1;
  while (n--) {
    scanf("%lld%lld", &a, &b);
    ans = gcd(ans, a * b / gcd(a, b));
  }
  if (ans == 1)
    puts("-1");
  else {
    if (gcd(ans, a) > 1)
      printf("%lld\n", solve(gcd(ans, a)));
    else
      printf("%lld\n", solve(gcd(ans, b)));
  }
  return 0;
}
