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.
#include <bits/stdc++.h>
using namespace std;
bool second[1111111];
long long int first[1111111];
long long int fibo[1111111];
long long int gcd(long long int x, long long int y) {
  if (!y) return x;
  return gcd(y, x % y);
}
long long int fibonacci(long long int x) {
  fibo[1] = fibo[2] = 1;
  if (x < 1111111 && !fibo[x]) return fibo[x];
  if (x < 1111111)
    return fibo[x] = (fibonacci(x - 1) + fibonacci(x - 2)) % 1000000007;
  return fibo[x] = (fibonacci(x - 1) + fibonacci(x - 2)) % 1000000007;
}
long long int mul(long long int a, long long int b, long long int m) {
  long long int result = 0;
  a %= m;
  while (b) {
    if (b & 1) result = (result + a) % m;
    a = (2 * a) % m;
    b >>= 1;
  }
  return result;
}
long long int power(long long int b, long long int e, long long int m) {
  long long int result = 1;
  b %= m;
  while (e) {
    if (e & 1) result = mul(result, b, m);
    e >>= 1;
    b = mul(b, b, m);
  }
  return result;
}
bool func1(pair<long long int, long long int> x,
           pair<long long int, long long int> y) {
  if (x.first == y.first) return x.second < y.second;
  return x.first < y.first;
}
bool func2(pair<long long int, long long int> x,
           pair<long long int, long long int> y) {
  if (x.second == y.second) return x.first < y.first;
  return x.second < y.second;
}
bool dfunc(long long int a, long long int b) { return a > b; }
long long int fact(long long int x) {
  if (x <= 1) return first[x] = 1;
  if (first[x]) return first[x];
  if (x < 1111111) return first[x] = x * fact(x - 1);
  return x * fact(x - 1);
}
void seive() {
  for (long long int i = 2; i < 1111111; i++)
    if (!second[i])
      for (long long int j = i * i; j < 1111111; j += i) second[j] = true;
}
vector<vector<long long int>> adj(1111111);
bool visited[1111111];
queue<long long int> q;
vector<long long int> side(1111111, -1);
long long int cover1, cover2;
bool isbi = true;
void dfs(long long int n) {
  visited[n] = true;
  for (long long int i : adj[n])
    if (!visited[i]) dfs(i);
}
void bibfs(long long int n) {
  long long int second;
  for (second = 1; second <= n; second++)
    if (side[second] == -1) {
      q.push(second);
      side[second] = 0;
      cover1++;
      while (!q.empty()) {
        long long int temp = q.front();
        q.pop();
        for (long long int j : adj[temp])
          if (side[j] == -1) {
            q.push(j);
            side[j] = side[temp] ^ 1;
            if (!side[j])
              cover1++;
            else
              cover2++;
          } else
            isbi &= (side[j] != side[temp]);
      }
    }
}
void bfs(long long int n) {
  q.push(n);
  while (!q.empty()) {
    long long int temp = q.front();
    q.pop();
    visited[temp] = true;
    for (long long int j : adj[temp])
      if (!visited[j]) q.push(j);
  }
}
vector<vector<pair<long long int, long long int>>> adj1(1111111);
void dk(long long int n, long long int second, vector<long long int> &d,
        vector<long long int> &p) {
  long long int i, j, v;
  d[second] = 0;
  vector<bool> u(n + 5, false);
  for (i = 1; i <= n; i++) {
    v = -1;
    for (j = 1; j <= n; j++)
      if (!u[j] && (v == -1 || d[j] < d[v])) v = j;
    u[v] = true;
    if (d[v] == ((long long int)INT_MAX) * 1000) break;
    for (pair<long long int, long long int> temp : adj1[v])
      if (d[v] + temp.second < d[temp.first]) {
        d[temp.first] = d[v] + temp.second;
        p[temp.first] = v;
      }
  }
}
long long int sakamoto(long long int d, long long int m, long long int y) {
  long long int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
  if (m < 3) y -= 1;
  return ((y + y / 4 - y / 100 + y / 400 + t[m - 1] + d) % 7);
}
long long int seg1[1111111];
vector<long long int> a;
void build(long long int left, long long int right, long long int index) {
  if (left == right) {
    seg1[index] = a[left];
    return;
  }
  long long int mid = (left + right) / 2;
  build(left, mid, 2 * index);
  build(mid + 1, right, 2 * index + 1);
  seg1[index] = seg1[2 * index] + seg1[2 * index + 1];
}
long long int query(long long int left, long long int right,
                    long long int lindex, long long int rindex,
                    long long int index) {
  if (right < lindex || rindex < left) return 0;
  if (left <= lindex && right >= rindex) return seg1[index];
  return query(left, right, lindex, (lindex + rindex) / 2, 2 * index) +
         query(left, right, (lindex + rindex) / 2 + 1, rindex, 2 * index + 1);
}
bool check(long long int n, long long int a, long long int d,
           long long int second) {
  long long int x = power(a, d, n);
  if (x == 1 || x == n - 1) return false;
  for (long long int i = 1; i < second; i++) {
    x = mul(x, x, n);
    if (x == n - 1) return false;
  }
  return true;
}
bool miller(long long int n, long long int iter) {
  srand(time(0));
  if (n < 4) return n == 2 || n == 3;
  long long int d = n - 1;
  long long int second = 0;
  while (!(d & 1)) {
    d >>= 1;
    second++;
  }
  for (long long int i = 1; i <= iter; i++) {
    long long int a = 2 + rand() % (n - 3);
    if (check(n, a, d, second)) return false;
  }
  return true;
}
long long int arr[1111111];
long long int ceilindex(vector<long long int> &v, long long int l,
                        long long int r, long long int val) {
  while ((r - l) > 1) {
    long long int mid = (l + r) >> 1;
    if (v[mid] >= val)
      r = mid;
    else
      l = mid;
  }
  return r;
}
long long int lis(long long int n) {
  long long int i, length = 1;
  vector<long long int> tail(n, 0);
  tail[0] = arr[0];
  for (i = 1; i < n; i++) {
    if (arr[i] < tail[0])
      tail[0] = arr[i];
    else if (arr[i] > tail[length - 1])
      tail[length++] = arr[i];
    else
      tail[ceilindex(tail, 0, length - 1, arr[i])] = arr[i];
  }
  return length;
}
vector<pair<long long int, long long int>> lst;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t = 1;
  while (t--) {
    long long int n, i, a, b;
    set<long long int> s1, s2;
    cin >> n;
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      lst.push_back(make_pair(a, b));
    }
    while (!(lst[0].first % 2)) {
      s1.insert(2);
      lst[0].first /= 2;
    }
    for (i = 3; i * i <= lst[0].first; i += 2)
      while (!(lst[0].first % i)) {
        s1.insert(i);
        lst[0].first /= i;
      }
    while (!(lst[0].second % 2)) {
      s1.insert(2);
      lst[0].second /= 2;
    }
    for (i = 3; i * i <= lst[0].second; i += 2)
      while (!(lst[0].second % i)) {
        s1.insert(i);
        lst[0].second /= i;
      }
    for (i = 1; i < n; i++) {
      s2.clear();
      for (long long int x : s1)
        if (lst[i].first % x && lst[i].second % x)
          continue;
        else
          s2.insert(x);
      s1.clear();
      for (long long int x : s2) s1.insert(x);
    }
    if (!s1.size())
      cout << "-1" << endl;
    else
      cout << *s1.begin() << endl;
  }
  return 0;
}
