#include <bits/stdc++.h>
using namespace std;
const int N = 150005;
const int q = 600005;
long long n, a[N], b[N];
long long qwq, ans = 19260817000;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i] >> b[i];
    qwq = gcd(qwq, 1ll * b[i] * a[i] / gcd(b[i], a[i]));
  }
  if (qwq == 1) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; ++i) {
    long long x = gcd(qwq, a[i]);
    if (x > 1) qwq = x;
    long long y = gcd(qwq, b[i]);
    if (y > 1) qwq = y;
  }
  printf("%I64d\n", qwq);
  return 0;
}
