#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " = " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " |";
  __f(comma + 1, args...);
}
int n;
vector<pair<long long, long long> > a;
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(NULL);
  std::cout.tie(NULL);
  cin >> n;
  long long x1, y1;
  long long sm = 2e18;
  for (long long i = 0; i < n; i++) {
    long long x, y;
    cin >> x >> y;
    if (x + y < sm) {
      sm = x + y;
      x1 = x;
      y1 = y;
    }
    a.push_back({x, y});
  }
  vector<long long> xfac, yfac;
  if (x1 % 2 == 0) {
    xfac.push_back(2);
    while (x1 % 2 == 0) {
      x1 /= 2;
    }
  }
  for (int i = 3; i * i <= x1; i += 2) {
    if (x1 % i == 0) {
      xfac.push_back(i);
      while (x1 % i == 0) {
        x1 /= i;
      }
    }
  }
  if (x1 > 2) xfac.push_back(x1);
  if (y1 % 2 == 0) {
    yfac.push_back(2);
    while (y1 % 2 == 0) {
      y1 /= 2;
    }
  }
  for (int i = 3; i * i <= y1; i += 2) {
    if (y1 % i == 0) {
      yfac.push_back(i);
      while (y1 % i == 0) {
        y1 /= i;
      }
    }
  }
  if (y1 > 2) yfac.push_back(y1);
  for (auto i : xfac) {
    bool pos = 1;
    for (auto j : a) {
      if ((j.first % i) && (j.second % i)) {
        pos = 0;
      }
      if (!pos) break;
    }
    if (pos) {
      cout << i;
      return 0;
    }
  }
  for (auto i : yfac) {
    bool pos = 1;
    for (auto j : a) {
      if ((j.first % i) && (j.second % i)) {
        pos = 0;
      }
      if (!pos) break;
    }
    if (pos) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
