Problem: During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.

For a given list of pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_n, b_n) their WCD is arbitrary integer greater than 1, such that it divides at least one element in each pair. WCD may not exist for some lists.

For example, if the list looks like [(12, 15), (25, 18), (10, 24)], then their WCD can be equal to 2, 3, 5 or 6 (each of these numbers is strictly greater than 1 and divides at least one number in each pair).

You're currently pursuing your PhD degree under Ildar's mentorship, and that's why this problem was delegated to you. Your task is to calculate WCD efficiently.

Input

The first line contains a single integer n (1 ≤ n ≤ 150 000) — the number of pairs.

Each of the next n lines contains two integer values a_i, b_i (2 ≤ a_i, b_i ≤ 2 ⋅ 10^9).

Output

Print a single integer — the WCD of the set of pairs. 

If there are multiple possible answers, output any; if there is no answer, print -1.

Examples

Input

3
17 18
15 24
12 15


Output

6

Input

2
10 16
7 17


Output

-1


Input

5
90 108
45 105
75 40
165 175
33 30


Output

5

Note

In the first example the answer is 6 since it divides 18 from the first pair, 24 from the second and 12 from the third ones. Note that other valid answers will also be accepted.

In the second example there are no integers greater than 1 satisfying the conditions.

In the third example one of the possible answers is 5. Note that, for example, 15 is also allowed, but it's not necessary to maximize the output.

Solution (in CPP):

Solution:
#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();
}