#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
inline unsigned long long readl() {
  unsigned long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int power(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = ans * a;
    b >>= 1;
    a = a * a;
  }
  return ans;
}
int power_mod(int a, int b, int mod) {
  a %= mod;
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % mod;
    b >>= 1, a = (a * a) % mod;
  }
  return ans;
}
unsigned long long powerl(unsigned long long a, unsigned long long b) {
  unsigned long long ans = 1ll;
  while (b) {
    if (b & 1ll) ans = ans * a;
    b >>= 1ll;
    a = a * a;
  }
  return ans;
}
unsigned long long power_modl(unsigned long long a, unsigned long long b,
                              unsigned long long mod) {
  a %= mod;
  unsigned long long ans = 1ll;
  while (b) {
    if (b & 1ll) ans = (ans * a) % mod;
    b >>= 1ll, a = (a * a) % mod;
  }
  return ans;
}
unsigned long long gcdl(unsigned long long a, unsigned long long b) {
  return b == 0 ? a : gcdl(b, a % b);
}
unsigned long long abssl(unsigned long long a) { return a > 0 ? a : -a; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int abss(int a) { return a > 0 ? a : -a; }
inline int read();
inline unsigned long long readl();
int power(int a, int b);
int power_mod(int a, int b, int mod);
int gcd(int a, int b);
int abssl(int a);
unsigned long long powerl(unsigned long long a, unsigned long long b);
unsigned long long power_modl(unsigned long long a, unsigned long long b,
                              unsigned long long mod);
unsigned long long gcdl(unsigned long long a, unsigned long long b);
unsigned long long abssl(unsigned long long a);
unsigned long long n, a[150000 + 5], b[150000 + 5];
set<unsigned long long> s;
void gg(unsigned long long x) {
  if (x != 1ull) s.insert(x);
  for (unsigned long long i = 2ull; i * i <= x; i++) {
    if (x % i == 0ull) {
      s.insert(i);
      while (x % i == 0ull) x /= i;
    }
  }
  if (x != 1ull) s.insert(x);
}
int main() {
  cin >> n;
  for (unsigned long long i = 1ull; i <= n; i++) cin >> a[i] >> b[i];
  gg(a[1ull]), gg(b[1ull]);
  for (set<unsigned long long>::iterator it = s.begin(); it != s.end(); it++) {
    unsigned long long fa = *it, fl = 0ull;
    for (unsigned long long i = 2ull; i <= n; i++) {
      if ((a[i] % fa != 0ull) && (b[i] % fa != 0ull)) {
        fl = 1ull;
        break;
      }
    }
    if (fl)
      continue;
    else
      return cout << fa, 0;
  }
  return cout << -1, 0;
  return 0;
}
