#include <bits/stdc++.h>
using namespace std;
const int N = 150005;
struct node {
  long long x;
  long long y;
} a[N];
long long prime[N], p1[N], p2[N];
long long n, m1, m2;
void divide1(int n) {
  m1 = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      p1[++m1] = i;
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) p1[++m1] = n;
}
void divide2(int n) {
  m2 = 0;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      p2[++m2] = i;
      while (n % i == 0) n /= i;
    }
  }
  if (n > 1) p2[++m2] = n;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d %d", &a[i].x, &a[i].y);
  divide1(a[1].x);
  divide2(a[1].y);
  long long j = 0;
  int x = 0;
  for (int i = 1; i <= m1; i++) {
    prime[x] = p1[i], x++;
  }
  for (int i = 1; i <= m2; i++) {
    prime[x] = p2[i], x++;
  }
  long long ans = 0;
  int flag = 0;
  for (int i = 0; i < x; i++) {
    for (j = 2; j <= n; j++) {
      if (a[j].x % prime[i] == 0 || a[j].y % prime[i] == 0) {
        continue;
      } else
        break;
    }
    if (j > n) {
      ans = prime[i];
      flag = 1;
      break;
    }
  }
  if (flag)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
