#include <bits/stdc++.h>
using namespace std;
vector<long long> v;
void prime(long long x) {
  for (long long i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      v.push_back(i);
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) v.push_back(x);
}
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    long long a, b;
    scanf("%I64d%I64d", &a, &b);
    prime(a);
    prime(b);
    vector<long long>::iterator it = unique(v.begin(), v.end());
    v.erase(it, v.end());
    for (int i = 1; i < n; i++) {
      scanf("%I64d%I64d", &a, &b);
      for (it = v.begin(); it != v.end(); it++) {
        if (a % *it && b % *it) {
          v.erase(it);
          it--;
        }
      }
    }
    if (v.size())
      printf("%I64d\n", v[0]);
    else
      printf("-1\n");
  }
  return 0;
}
