#include <bits/stdc++.h>
using namespace std;
set<long long int> getFactors(long long int d) {
  set<long long int> factors1;
  for (long long int i = 2; i * i <= d; i++) {
    if (d % i == 0) {
      factors1.insert(i);
      while (d % i == 0) {
        d /= i;
      }
    }
  }
  if (d > 1) factors1.insert(d);
  return factors1;
}
int main() {
  long long int n, f, s;
  cin >> n;
  long long int A[n], B[n];
  for (int i = 0; i < n; ++i) {
    cin >> A[i] >> B[i];
  }
  set<long long int> factors1 = getFactors(A[0]);
  set<long long int> factors2 = getFactors(B[0]);
  for (long long int var : factors1) {
    bool all = true;
    for (long long int i = 0; i < n; i++) {
      if (A[i] % var != 0 and B[i] % var != 0) {
        all = false;
        break;
      }
    }
    if (all) {
      cout << var << endl;
      return 0;
    }
  }
  for (long long int var : factors2) {
    bool all = true;
    for (long long int i = 0; i < n; i++) {
      if (A[i] % var != 0 and B[i] % var != 0) {
        all = false;
        break;
      }
    }
    if (all) {
      cout << var << endl;
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
