#include <bits/stdc++.h>
using namespace std;
int debug = 0.0;
int debug_test = 0;
int _t = 0;
typedef vector<vector<int> > matrix;
const long long int mod = 1e9 + 7;
template <class T>
long long int sz(T &x) {
  return (long long int)x.size();
}
template <class T>
void show(T first) {
  if (debug and (debug_test == 0 or _t == debug_test))
    cout << " " << first << "\n";
}
template <class T, class... Args>
void show(T first, Args... args) {
  if (debug and (debug_test == 0 or _t == debug_test)) cout << " " << first;
  show(args...);
}
template <class T, class U>
ostream &operator<<(ostream &os, pair<T, U> &x) {
  return os << x.first << "," << x.second;
}
template <class T>
bool sort_fun(T a, T b) {
  return a > b;
}
struct Desc {
  bool operator()(long long int a, long long int b) { return a > b; }
} desc;
const long long int range = 32000;
vector<long long int> primes;
void sieve(set<long long int> &p) {
  vector<long long int> vec(range, 1);
  vec[0] = 0;
  vec[1] = 0;
  for (long long int i = 2; i < range; i++)
    if (vec[i] == 1)
      for (long long int j = 2 * i; j < range; j += i) vec[j] = 0;
  for (long long int i = 2; i < range; i++)
    if (vec[i] == 1) p.insert(i), primes.push_back(i);
}
bool is_prime(long long int n) {
  long long int i = 0;
  for (; i < (long long int)primes.size() and primes[i] <= sqrt(n); i++)
    if (n % primes[i] == 0) return false;
  for (long long int i = *primes.rbegin(); i <= sqrt(n); i++)
    if (n % i == 0) return false;
  return true;
}
set<long long int> factorise(long long int a, long long int b,
                             set<long long int> primes, long long int x) {
  set<long long int> f;
  for (auto p : primes) {
    if (a <= 1 and p > a) break;
    if (a % p == 0) f.insert(p), a /= p;
    while (a % p == 0 and a > 1) a /= p;
  }
  if (x == 0 and a > 1 and is_prime(a)) f.insert(a);
  for (auto p : primes) {
    if (b <= 1 and p > b) break;
    if (b % p == 0) f.insert(p), b /= p;
    while (b % p == 0 and b > 1) b /= p;
  }
  if (x == 0 and b > 1 and is_prime(b)) f.insert(b);
  return f;
}
long long int temp = -1, last = -1;
void solve() {
  long long int n, a, b;
  cin >> n;
  set<long long int> primes;
  sieve(primes);
  vector<pair<long long int, long long int> > vec(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a >> b;
    vec[i] = {a, b};
  }
  for (long long int i = 0; i < n; i++) {
    primes = factorise(vec[i].first, vec[i].second, primes, i);
  }
  if (primes.size() == 0)
    cout << "-1" << endl;
  else
    cout << *primes.begin() << endl;
}
signed main() {
  long long int test = 1;
  for (long long int t = 1; t <= test; t++) _t = t, solve();
}
