#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
long long p[maxn], num[maxn], k, a[maxn], b[maxn];
void prime() {
  for (int i = 2; i < maxn; i++) {
    if (!num[i]) {
      for (long long j = 1LL * i * i; j < maxn; j += i) {
        num[j] = 1;
      }
    }
  }
  k = 0;
  for (int i = 2; i < maxn; i++) {
    if (!num[i]) p[++k] = i;
  }
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  int n;
  long long x, y, a, b, sa, sb;
  prime();
  while (scanf("%d", &n) != EOF) {
    scanf("%lld%lld", &x, &y);
    num[1] = x * y;
    if (n == 1) {
      printf("%lld\n", x);
      continue;
    }
    for (int i = 1; i <= k && x >= p[i]; i++) {
      while (x % p[i] == 0) {
        x /= p[i];
      }
    }
    if (x == 1)
      a = 2e9 + 10;
    else
      a = x;
    for (int i = 1; i <= k && y >= p[i]; i++) {
      while (y % p[i] == 0) {
        y /= p[i];
      }
    }
    if (y == 1)
      b = 2e9 + 10;
    else
      b = y;
    sa = sb = 1;
    for (int i = 2; i <= n; i++) {
      scanf("%lld%lld", &x, &y);
      num[i] = x * y;
      if (x % a == 0 || y % a == 0) sa++;
      if (y % b == 0 || x % b == 0) sb++;
    }
    if (sa == n) {
      printf("%lld\n", a);
      continue;
    } else if (sb == n) {
      printf("%lld\n", b);
      continue;
    }
    long long Gcd = num[1];
    for (int i = 2; i <= n; i++) Gcd = gcd(num[i], Gcd);
    int ans = 0;
    for (int i = 1; i <= k; i++) {
      if (Gcd % p[i] == 0) {
        ans = p[i];
        break;
      }
    }
    if (ans == 0 && Gcd != 1)
      printf("%lld\n", Gcd);
    else if (ans == 0 && Gcd == 1)
      printf("-1\n");
    else
      printf("%d\n", ans);
  }
  return 0;
}
