#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  set<long long int> c;
  for (long long int j = 1; j <= sqrt(a[0]); j++) {
    if (a[0] % j == 0) {
      c.insert(j);
      c.insert(a[0] / j);
    }
  }
  for (long long int j = 1; j <= sqrt(b[0]); j++) {
    if (b[0] % j == 0) {
      c.insert(j);
      c.insert(b[0] / j);
    }
  }
  c.erase(1);
  vector<long long int> v, vec;
  for (auto itr = c.begin(); itr != c.end(); ++itr) {
    vec.push_back(*itr);
  }
  for (int i = 0; i < vec.size(); i++) {
    long long int a = 0;
    for (long long int j = 2; j <= sqrt(vec[i]); j++) {
      if (vec[i] % j == 0) {
        a = 1;
        break;
      }
    }
    if (a == 0) {
      v.push_back(vec[i]);
    }
  }
  for (int i = 1; i < n; i++) {
    vector<long long int> aaa;
    for (int j = 0; j < v.size(); j++) {
      if (a[i] % v[j] == 0 || b[i] % v[j] == 0) {
        aaa.push_back(v[j]);
      }
    }
    if (aaa.size() == 0) {
      cout << -1;
      return 0;
    }
    v = aaa;
  }
  cout << v[0];
}
