#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int inf = 0x3f3f3f3f;
long long n, m, p[maxn];
set<int> prime;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
void find(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      prime.insert(i);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) prime.insert(x);
}
int main() {
  int i, j;
  prime.clear();
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    long long x, y, te;
    scanf("%I64d %I64d", &x, &y);
    if (i == 1) {
      find(x);
      find(y);
    }
    te = gcd(x, y);
    p[i] = x * y / te;
  }
  long long t = p[1];
  for (long long i = 2; i <= n; i++) {
    t = gcd(t, p[i]);
  }
  set<int>::iterator it;
  for (it = prime.begin(); it != prime.end(); it++) {
    if (t % (*it) == 0) {
      t = *it;
      break;
    }
  }
  if (t == 1)
    printf("-1\n");
  else {
    printf("%lld\n", t);
  }
  return 0;
}
