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:
import java.util.*;
import java.io.*;
import java.awt.Point;
import java.math.BigInteger;

public class bbetter {
	
	static TreeSet<Integer> primes = new TreeSet<Integer>();
	
	public static void main(String[] args) throws Exception {
		FastIO sc = new FastIO(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		for(int i = 2; i < 45000; i++) {
			int sqrt = (int) Math.ceil(Math.sqrt(i));
			boolean bad = false;
			for(int j : primes) {
				if(j > sqrt) continue;
				if(i % j == 0) {
					bad = true;
					break;
				}
			}
			if(!bad) primes.add(i);
		}
		
		int N = sc.nextInt();
		
		int a =sc.nextInt();
		int b = sc.nextInt();
		int firstA = a;
		int firstB = b;
		
		
		for(int prime : primes) {
			if(firstA % prime == 0) {
				while(firstA % prime == 0) firstA /= prime;
			};
		}
		if(firstA != 1) primes.add(firstA);
		
		for(int prime : primes) {
			if(firstB % prime == 0) {
				while(firstB % prime == 0) firstB /= prime;
			};
		}
		if(firstB != 1) primes.add(firstB);
		
		for(int i = 0; i < N; i++) {
			for(int prime : primes) {
				if(a % prime != 0 && b % prime != 0) remove(prime);
			}
			remove();
			
			if(i != N-1) {
				a = sc.nextInt();
				b = sc.nextInt();
			}
		}
		
		if(!primes.isEmpty()) pw.println(primes.first());
		else pw.println(-1);
		pw.close();
	}
	
	static Queue<Integer> toRemove = new ArrayDeque<Integer>();
	
	static void remove(int a) {
		toRemove.add(a);
	}
	
	static void remove() {
		while(!toRemove.isEmpty()) primes.remove(toRemove.poll());
	}
	
	static long GCD(long a, long b) {
		if (b==0) return a;
		return GCD(b,a%b);
	}

	static class FastIO {

		InputStream dis;
		byte[] buffer = new byte[1 << 17];
		int pointer = 0;

		public FastIO(String fileName) throws Exception {
			dis = new FileInputStream(fileName);
		}

		public FastIO(InputStream is) throws Exception {
			dis = is;
		}

		int nextInt() throws Exception {
			int ret = 0;

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b >= '0' && b <= '9') {
				ret = 10 * ret + b - '0';
				b = nextByte();
			}

			return ret;
		}

		byte nextByte() throws Exception {
			if (pointer == buffer.length) {
				dis.read(buffer, 0, buffer.length);
				pointer = 0;
			}
			return buffer[pointer++];
		}

		String next() throws Exception {
			StringBuffer ret = new StringBuffer();

			byte b;
			do {
				b = nextByte();
			} while (b <= ' ');
			while (b >= 'a' && b <= 'z') {
				ret.appendCodePoint(b);
				b = nextByte();
			}

			return ret.toString();
		}

	}
}