#include <bits/stdc++.h>
using namespace std;
int sqrt(int n) {
  long long l = 0, r = 100000, m;
  while (r - l > 1) {
    m = (l + r) / 2;
    if (m * m <= n)
      l = m;
    else
      r = m;
  }
  return int(l);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  int a1, b1;
  cin >> a1 >> b1;
  set<int> p;
  for (int i = 2; i <= sqrt(a1); ++i) {
    if (a1 % i == 0) {
      p.insert(i);
      while (a1 % i == 0) {
        a1 /= i;
      }
    }
  }
  if (a1 > 1) p.insert(a1);
  for (int i = 2; i <= sqrt(b1); ++i) {
    if (b1 % i == 0) {
      p.insert(i);
      while (b1 % i == 0) {
        b1 /= i;
      }
    }
  }
  if (b1 > 1) p.insert(b1);
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    vector<int> del;
    for (auto now = p.begin(); now != p.end(); ++now) {
      if (a % *now != 0 && b % *now != 0) {
        del.push_back(*now);
      }
    }
    for (int j = 0; j < (int)del.size(); ++j) p.erase(del[j]);
  }
  p.empty() ? cout << -1 << endl : cout << *p.begin();
  return 0;
}
