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.*;
import java.util.*;

public class Question {
	public static int MOD = 1000000007;

	static Scan scn = new Scan();
	static Print printer = new Print();

	public static void main(String[] args) throws Exception {

		B();
		printer.close();
	}

	public static void A() throws Exception {

		int len = scn.scanInt();
		String str = scn.scanString();

		if (len == 1) {
			printer.printLine("Yes");
			return;
		}

		int[] hash = new int[26];

		for (int i = 0; i < str.length(); i++) {
			char ch = str.charAt(i);
			hash[ch - 'a']++;
		}

		for (int i = 0; i < hash.length; i++) {
			if (hash[i] > 1) {
				printer.printLine("Yes");
				return;
			}
		}

		printer.printLine("No");

	}

	public static void B() throws Exception {

		int n = scn.scanInt();
		IntIntPair[] arr = new IntIntPair[n];

		IntIntPair minPair = new IntIntPair(Integer.MAX_VALUE, Integer.MAX_VALUE);

		for (int i = 0; i < n; i++) {
			arr[i] = new IntIntPair(scn.scanInt(), scn.scanInt());

			if (arr[i].compareTo(minPair) < 0)
				minPair = arr[i];
		}

		HashSet<Integer> candidates = new HashSet<>();
		getAllUniquePrimeFactors(minPair.one, candidates);
		getAllUniquePrimeFactors(minPair.two, candidates);

		for (int i = 0; i < arr.length; i++) {

			HashSet<Integer> hs = new HashSet<>();
			for (int factor : candidates) {
				if (arr[i].one % factor == 0 || arr[i].two % factor == 0)
					hs.add(factor);
			}

			if (hs.size() == 0) {
				printer.printLine("-1");
				return;
			}

			candidates = hs;

		}

		printer.print(candidates.toArray()[0].toString());

	}

	public static class IntIntPair implements Comparable<IntIntPair> {

		int one;
		int two;

		public IntIntPair(int one, int two) {
			this.one = one;
			this.two = two;
		}

		@Override
		public int compareTo(IntIntPair o) {
			// TODO Auto-generated method stub
			int val = this.one - o.one;
			if (val != 0)
				return val;

			return this.two - o.two;
		}
	}

	public static void getAllUniquePrimeFactors(int num, HashSet<Integer> hs) {

		while (num % 2 == 0) {
			hs.add(2);
			num /= 2;
		}

		for (int fac = 3; fac <= Math.sqrt(num); fac += 2) {

			if (fac > num)
				break;

			if (num % fac == 0) {
				hs.add(fac);

				while (num % fac == 0)
					num /= fac;
			}
		}

		if (num > 2)
			hs.add(num);

	}

	public static int gcd(int one, int two) {

		return 0;
	}

	static class Scan {
		private InputStream in;
		private byte[] buf = new byte[1024 * 1024];
		private int index;
		private int total;

		public Scan() {
			// this.in = in;
			in = System.in;
			// try {
			// in = new FileInputStream(new File("/home/ujjwal/test/test"));
			// } catch (Exception ex) {
			//
			// }
		}

		public int scan() throws IOException {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				total = in.read(buf);
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public int[] inputArray(int n) throws Exception {
			int[] arr = new int[n];

			for (int i = 0; i < n; i++) {
				arr[i] = scn.scanInt();
			}

			return arr;
		}

		public ArrayList<Integer> inputList(int n) throws Exception {

			ArrayList<Integer> list = new ArrayList<>();
			for (int i = 0; i < n; i++) {
				list.add(scn.scanInt());
			}

			return list;
		}

		public int[][] inputMatrix(int n, int m) throws Exception {
			int[][] arr = new int[n][m];

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					arr[i][j] = scn.scanInt();
				}
			}

			return arr;
		}

		public int scanInt() throws IOException {
			int integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public long scanLong() throws IOException {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() throws IOException {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}

	static class Print {
		private final BufferedWriter bw;

		public Print() {
			bw = new BufferedWriter(new OutputStreamWriter(System.out));
		}

		public void print(String str) throws IOException {
			bw.append(str);
		}

		public void printArray(int[] arr) throws Exception {

			for (int i = 0; i < arr.length; i++) {
				printer.print(arr[i] + " ");
			}

			printer.printLine("");
		}

		public void printList(ArrayList<Integer> list) throws Exception {

			for (int i = 0; i < list.size(); i++) {
				printer.print(list.get(i) + " ");
			}

			printer.printLine("");
		}

		public void printLine(String str) throws IOException {
			print(str);
			bw.append("\n");
		}

		public void close() throws IOException {
			bw.close();
		}
	}

}