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.
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class CF {
    static List<Integer>[] gr;

    static long[] arr;
    static long n, m, p, q, k, ans;
    static boolean b;
    static long s;

    static String big;
    static long sum;

    static boolean check(long mid) {
	return s - mid * (k - 1) <= mid && s - mid * (k - 1) >= 0;
    }

    public static Set<Integer> f(long n) {
	Set<Integer> factors = new HashSet<>();
	for (long d = 2; d * d <= n; d++) {
	    while (n % d == 0) {
		factors.add((int) d);
		n /= d;
	    }
	}
	if (n > 1) {
	    factors.add((int) n);
	}
	return factors;
    }

    public static void main(String[] args) {
	n = in.nextLong();
//	k = in.nextLong();
//	s = in.nextLong();
//	out.close();
	Set<Integer> set = new HashSet<>();
	set.addAll(f(in.nextLong()));
	set.addAll(f(in.nextLong()));
	for (int i = 1; i < n; i++) {
	    Set<Integer> newS = new HashSet<>();
	    for (int j = 0; j < 2; j++) {
		int N = in.nextInt();
		for (int div : set) {
		    if (N % div == 0) {
			newS.add(div);
		    }
		}
	    }
	    set = newS;
	}
	if (set.size() != 0)
	    System.out.println(new ArrayList<>(set).get(0));
	else
	    System.out.println(-1);
	out.close();
    }

    static MyScanner in = new MyScanner();
    static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

    static boolean valid(int[][] arr, int x, int y) {
	return x >= 0 && y >= 0 && x < arr.length && y < arr[0].length;
    }

    static int[] d1 = { -1, -1, -1, 1, 1, 1, 0, 0 };
    static int[] d2 = { 1, 0, -1, 0, -1, 1, -1, 1 };

    static int DIRECTED = 1, UNDIRECTED = 0;

    static long binSearch(long l, long r) {
	long ans = -1, mid = 0;
	while (l != r) {
	    mid = (l + r) / 2;
	    if (check(mid)) {
		ans = mid;
		l = mid + 1;
	    } else {
		r = mid;
	    }
	}
	return ans;
    }

    static void dfsTree(int root, int parent) {
	for (int child : gr[root]) {
	    if (child == parent) {
		continue;
	    }
	    dfsTree(child, root);
	}
    }

    static List<Integer>[] readGraph(int dir, int n) {
	List<Integer>[] gr;
	gr = new ArrayList[(int) (n + 1)];
	for (int i = 1; i <= n; i++) {
	    gr[i] = new ArrayList();
	}
	for (int i = 1; i < n; i++) {
	    int u = in.nextInt(), v = in.nextInt();
	    gr[v].add(u);
	    if (dir == UNDIRECTED) {
		gr[u].add(v);
	    }
	}
	return gr;
    }

    public static long gcd(long a, long b) {
	while (b != 0) {
	    long t = b;
	    b = a % b;
	    a = t;
	}
	return Math.abs(a);
    }

    public static long lcm(long a, long b) {
	return Math.abs(a / gcd(a, b) * b);
    }

    static class Pair implements Comparable<Pair> {
	long a, b;

	public Pair(long a, long b) {
	    this.a = a;
	    this.b = b;
	}

	@Override
	public int compareTo(Pair p) {
	    return a == p.a ? 0 : (a > p.a ? 1 : -1);
	}

	@Override
	public int hashCode() {
	    final int prime = 31;
	    int result = 1;
	    result = prime * result + (int) (a ^ (a >>> 32));
	    result = prime * result + (int) (b ^ (b >>> 32));
	    return result;
	}

	@Override
	public boolean equals(Object obj) {
	    if (this == obj)
		return true;
	    if (obj == null)
		return false;
	    if (getClass() != obj.getClass())
		return false;
	    Pair other = (Pair) obj;
	    if (a != other.a)
		return false;
	    if (b != other.b)
		return false;
	    return true;
	}
    }

    public static void sort(int[] arr) {
	List<Integer> l = new ArrayList<>();
	for (int i : arr) {
	    l.add(i);
	}
	Collections.sort(l);
	for (int i = 0; i < arr.length; i++) {
	    arr[i] = l.get(i);
	}
    }

    public static void sort(long[] arr) {
	List<Long> l = new ArrayList<>();
	for (long i : arr) {
	    l.add(i);
	}
	Collections.sort(l);
	for (int i = 0; i < arr.length; i++) {
	    arr[i] = l.get(i);
	}
    }

    public static class MyScanner {
	BufferedReader br;
	StringTokenizer st;

	public MyScanner() {
	    br = new BufferedReader(new InputStreamReader(System.in));
	}

	String next() {
	    while (st == null || !st.hasMoreElements()) {
		try {
		    st = new StringTokenizer(br.readLine());
		} catch (IOException e) {
		    e.printStackTrace();
		}
	    }
	    return st.nextToken();
	}

	int nextInt() {
	    return Integer.parseInt(next());
	}

	long nextLong() {
	    return Long.parseLong(next());
	}

	double nextDouble() {
	    return Double.parseDouble(next());
	}

	String nextLine() {
	    String str = "";
	    try {
		str = br.readLine();
	    } catch (IOException e) {
		e.printStackTrace();
	    }
	    return str;
	}
    }
}