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.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.List;
import java.util.Set;

public class Main {
	String INPUT = "";

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	static Set<Integer> factorize(long n) {
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;

		// count the number of times 2 divides
		while ((n % 2) == 0) {
			n >>= 1; // equivalent to n=n/2;
			count++;
		}

		// if 2 divides it
		if (count != 0) {
			set.add(2);
		}

		// check for all the possible numbers that can
		// divide it
		for (long i = 3; i <= Math.sqrt(n); i += 2) {
			count = 0;
			while (n % i == 0) {
				count++;
				n = n / i;
			}
			if (count > 0) {
				set.add((int) i);
			}
		}

		// if n at the end is a prime number.
		if (n > 2) {
			set.add((int) n);
		}
		return set;
	}

	private void solve() {
		int n = nextInt();
		int[] ar1 = new int[n];
		int[] ar2 = new int[n];
		for (int i = 0; i < n; i++) {
			ar1[i] = nextInt();
			ar2[i] = nextInt();
		}
		Set<Integer> factorize = factorize(ar1[0]);
		Integer answer = null;
		for (int j : factorize) {
			int count = 0;
			for (int i = 0; i < n; i++) {
				if (ar1[i] % j == 0 || ar2[i] % j == 0) {
					count++;
				}
			}
			if (count == n) {
				answer = j;
			}
		}
		if (answer == null) {
			factorize = factorize(ar2[0]);
			for (int j : factorize) {
				int count = 0;
				for (int i = 0; i < n; i++) {
					if (ar1[i] % j == 0 || ar2[i] % j == 0) {
						count++;
					}
				}
				if (count == n) {
					answer = j;
				}
			}
		}
		if (answer == null) {
			System.out.println(-1);
		} else {
			System.out.println(answer);
		}
	}

	InputStream is;
	PrintWriter out;

	void run() throws Exception {
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		// tr(System.currentTimeMillis() - s + "ms");
	}

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nextDouble() {
		return Double.parseDouble(nextString());
	}

	private char nextCharactor() {
		return (char) skip();
	}

	private String nextString() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=
									// ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] nextString(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nextMap(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = nextString(m);
		return map;
	}

	private int[] nextIntArr(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	private int nextInt() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nextLong() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = true;

	// System.getProperty("ONLINE_JUDGE") != null;

	private void tr(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}
}