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.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;

public class B {

	public static void main(String[] args) {
		JS in = new JS();
		boolean prime[] = new boolean[100000];
		Arrays.fill(prime, true);
		for(int i = 2; i < 100000; i++) {
			if(prime[i]) {
				for(int cur = 2*i; cur < 100000; cur += i) prime[cur] = false;
			}
		}
		
		int N = in.nextInt();
		int a1[] = new int[N];
		int a2[] = new int[N];
		int max1 = 0;
		int max2 = 0;
		for(int i = 0; i < N; i++) {
			a1[i] = in.nextInt();
			a2[i] = in.nextInt();
			if(Math.max(a1[i], a2[i]) > max1) {
				max1 = Math.max((int)a1[i], (int)a2[i]);
				if(max1 == a1[i]) max2 = (int)a2[i];
				else max2 = (int)a1[i];
			}
		}
		long res = -1;
		ArrayList<Integer> primes = new ArrayList<Integer>();
		primes.add(max1);
		primes.add(max2);
		primes.addAll(factor(a1[0]));
		primes.addAll(factor(a2[0]));
		
		for(Integer ii : primes) {
			for(int i = 0; i < N; i++) {
				if(a1[i]%ii != 0 && a2[i]%ii != 0) break;
				if(i == N-1) {
					res = ii;
					break;
				}
			}
			if(res != -1) break;
		}
		System.out.println(res);
		
	}
	
	static long gcd(long a, long b) {
		return b == 0 ? a : gcd(b, a%b);
	}

	//@
	// Factor a number n O(sqrt(n))
	static ArrayList<Integer> factor(int n) {
	  ArrayList<Integer> ans = new ArrayList<Integer>();
	  for(int x = 2; x * x <= n; x++) {
		  boolean added = false;
	    while(n % x == 0) {
	      n /= x;
	      if(!added)ans.add(x);
	      added = true;
	    }
	  }
	  if(n != 1)
	    ans.add(n);
	  return ans;
	}
	
	static class JS{
		public int BS = 1<<16;
		public char NC = (char)0;
		byte[] buf = new byte[BS];
		int bId = 0, size = 0;
		char c = NC;
		double num = 1;
		BufferedInputStream in;
		
		public JS() {
			in = new BufferedInputStream(System.in, BS);
		}
		
		public JS(String s) throws FileNotFoundException {
			in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
		}
		
		public char nextChar(){
			while(bId==size) {
				try {
					size = in.read(buf);
				}catch(Exception e) {
					return NC;
				}				
				if(size==-1)return NC;
				bId=0;
			}
			return (char)buf[bId++];
		}
		
		public int nextInt() {
			return (int)nextLong();
		}
		
		public long nextLong() {
			num=1;
			boolean neg = false;
			if(c==NC)c=nextChar();
			for(;(c<'0' || c>'9'); c = nextChar()) {
				if(c=='-')neg=true;
			}
			long res = 0;
			for(; c>='0' && c <='9'; c=nextChar()) {
				res = (res<<3)+(res<<1)+c-'0';
				num*=10;
			}
			return neg?-res:res;
		}
		
		public double nextDouble() {
		    while(c!='.'&&c!='-'&&(c <'0' || c>'9')) c = nextChar();
		    boolean neg = c=='-';
		    if(neg)c=nextChar();
		    boolean fl = c=='.';
		    double cur = nextLong();
		    if(fl) return neg ? -cur/num : cur/num;
		    if(c == '.') {
			double next = nextLong();
			return neg ? -cur-next/num : cur+next/num;
		    }
		    else return neg ? -cur : cur;
		}
		
		public String next() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c>32) {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}
		
		public String nextLine() {
			StringBuilder res = new StringBuilder();
			while(c<=32)c=nextChar();
			while(c!='\n') {
				res.append(c);
				c=nextChar();
			}
			return res.toString();
		}

		public boolean hasNext() {
			if(c>32)return true;
			while(true) {
				c=nextChar();
				if(c==NC)return false;
				else if(c>32)return true;
			}
		}
	}
	
}