#include <bits/stdc++.h>
void read(int &x);
void read(int &x);
using namespace std;
const int MAX = 150000 + 5;
const int INF = 0x3f3f3f3f;
long long MOD = 1000000000 + 7;
long long n, m, k, t;
int a[MAX];
int b[MAX];
int pri[110000], len;
int gcd(int a, int b) { return b ? a : gcd(b, a % b); }
set<int> s;
void slove(int x) {
  for (int i = 2; i <= sqrt(x + 0.5); i++)
    if (x % i == 0) {
      if (s.find(i) == s.end()) pri[++len] = i, s.insert(i);
      while (x % i == 0) x /= i;
    }
  if (x != 1 && s.find(x) == s.end()) pri[++len] = x, s.insert(x);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    read(a[i]);
    read(b[i]);
  }
  slove(a[1]);
  slove(b[1]);
  for (int i = 1; i <= len; i++) {
    bool flag = 1;
    for (int j = 1; j <= n; j++) {
      if (a[j] % pri[i] == 0 || b[j] % pri[i] == 0) continue;
      flag = 0;
      break;
    }
    if (flag) {
      printf("%d\n", pri[i]);
      return 0;
    }
  }
  printf("-1\n");
  return 0;
}
void read(int &x) {
  int f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
