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 JAVA):

Solution:
//package src;

import java.util.Scanner;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.math.BigInteger;

public class idk {
	static Scanner scn = new Scanner(System.in);
	static int mod = 1000000007;

	public static void main(String args[]) {

		int n=scn.nextInt();
		long arr[]=new long[n],brr[]=new long[n],a=0;
		arr[0]=scn.nextLong();brr[0]=scn.nextLong();
		a=arr[0]*brr[0];
		for(int i=1;i<n;i++)
		{
			arr[i]=scn.nextLong();
			brr[i]=scn.nextLong();
				a=gcd(arr[i]*brr[i],a);
		}
		
//		System.out.println(a);
		a=findgcd(arr, brr, n, a);
		if(n==1)
			System.out.println(arr[0]);
		else if(a>1)
			System.out.println(a);
		else 
			System.out.println("-1");

	}
	public static long findgcd(long arr[],long brr[],int n,long ans)
	{
		for (int i = 0; i < n; i++)
            ans = Math.max(gcd(ans,arr[i]),gcd(ans,brr[i]));
        return ans;
	}

	public static int binarysearch(Long arr[], int l, int r, int key) {
		int mid, ans = r;
		while (l <= r) {
			mid = l + (r - l) / 2;
			if (arr[mid] == key) {
				l = mid + 1;
				ans = mid;
			} else if (arr[mid] > key) {
				r = mid - 1;
				ans = r;
			} else {
				l = mid + 1;
			}

		}

		return ans;
	}

	public static boolean word(String arr[], String str, String ori, HashMap<String, Integer> map, int i, int j) {
		if (j == str.length()) { // System.out.println(str);
			if (str.length() == 0)
				return true;
			else
				return false;
		}

		String re = ori.substring(i, j);
		System.out.println(re);
		if (map.containsKey(re)) {
			String res = ori.substring(j);

			return word(arr, str, ori, map, j, j);
		}

		return word(arr, str, ori, map, i, j + 1);

	}

	public static int decode(String str, int i, int[] memo) {
		if (i == 0) {
			return 1;
		}
		int ind = str.length() - i;
		if (str.charAt(ind) == '0')
			return 0;
		if (memo[i] != -1)
			return memo[i];
		int res = decode(str, i - 1, memo);
		if (i >= 2 && Integer.parseInt(str.substring(ind, ind + 2)) <= 26) {
			res += decode(str, i - 2, memo);
		}
		memo[i] = res;
		return res;
	}

	public static long gcd(long a, long b) {
		if (a == 0)
			return  b;
		return  gcd(b % a, a);
	}

	public static String factorial(int n) {
		BigInteger fac = new BigInteger("1");
		for (int i = 1; i <= n; i++) {
			fac = fac.multiply(BigInteger.valueOf(i));
		}
		return fac.toString();
	}

}

class pair {
	int a;
	int b;

	pair(int x, int y) {
		this.a = x;
		this.b = y;
	}
}

class sorting implements Comparator<pair> {

	@Override
	public int compare(pair o1, pair o2) {
		// TODO Auto-generated method stub
		int x = o1.a - o2.a, y = o1.b - o2.b;
		if (y == 0) {
			if (x >= 0)
				return -1;
			else
				return 1;
		} else if (y > 0)
			return -1;
		else
			return 1;
	}

}