#include <bits/stdc++.h>
using namespace std;
long long int prime(long long int n) {
  if (n == 1) return 0;
  long long int i;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int a[n];
  long long int b[n];
  long long int i, j;
  for (i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  vector<long long int> v1, v2;
  long long int temp;
  for (i = 2; i < sqrt(a[0]); i++) {
    if (a[0] % i == 0) {
      if (prime(i) == 1) v1.push_back(i);
      if (prime(a[0] / i) == 1) v1.push_back(a[0] / i);
    }
  }
  temp = sqrt(a[0]);
  if ((temp * temp) == a[0] && prime(temp) == 1) v1.push_back(temp);
  if (prime(a[0]) == 1) v1.push_back(a[0]);
  for (i = 2; i < sqrt(b[0]); i++) {
    if (b[0] % i == 0) {
      if (prime(i) == 1) v2.push_back(i);
      if (prime(b[0] / i) == 1) v2.push_back(b[0] / i);
    }
  }
  temp = sqrt(b[0]);
  if ((temp * temp) == b[0] && prime(temp) == 1) v2.push_back(temp);
  if (prime(b[0]) == 1) v2.push_back(b[0]);
  long long int co = 0;
  for (i = 0; i < v1.size(); i++) {
    co = 0;
    for (j = 0; j < n; j++) {
      if (a[j] % v1[i] == 0 || b[j] % v1[i] == 0) {
        co++;
      }
    }
    if (co == n) {
      cout << v1[i];
      return 0;
    }
  }
  co = 0;
  for (i = 0; i < v2.size(); i++) {
    co = 0;
    for (j = 0; j < n; j++) {
      if (a[j] % v2[i] == 0 || b[j] % v2[i] == 0) {
        co++;
      }
    }
    if (co == n) {
      cout << v2[i];
      return 0;
    }
  }
  cout << "-1";
  return 0;
}
