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.
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <vector>
#include <numeric>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;
typedef long long int64;
typedef unsigned long long ll;
#define fi first
#define se second
/* */
#define all(x) begin(x),end(x)
#define rall(x) rbegin(x),rend(x)
#define forEach(i, s) for(auto i=begin(s);i!=end(s);i++)
#define for_each_n(i, s, n) for(auto i=begin(s),_5=next(i,n);i!=_5;i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int,int>
#define vec vector<int> 
#define lvec vector<ll>
#define dvec vector<double>

/* special */
#define Mem(x) memset(x,0,sizeof(x));
#define GET_MACRO(_0,_1,_2,_3,_NAME,...) _NAME
/* */
#define rep(...)  GET_MACRO(_0,##__VA_ARGS__,rep3,rep2,rep1,rep0)(__VA_ARGS__)
	#define rep3(i,a,b) for(int i=(a);i<(b);++i)
	#define rep2(i,a) for(int i=0;i<(a);++i)
	#define rep1(a) rep2(_,a)
	#define rep0()	
#define callOnce if([]{static int i=-1;i++;return !i;}())


/* input */
namespace my{
	#define put(x) cout<<(x)<<endl
	inline int in(int &x) {return scanf("%d",&x);}
	inline int in(double &x) {return scanf("%lf",&x);}
	inline int in(ll &x) {return scanf("%lld",&x);}
	inline int in(int &x,int &y) {return scanf("%d %d",&x,&y);}
	inline int in(int &x,int &y,int &z) {return scanf("%d %d %d",&x,&y,&z);}
	inline int in(char s[]) {return scanf("%s",s);}
	inline int in(char &c) {return scanf("%c",&c);}
}

using namespace my;

/* debug */
#ifndef ONLINE_JUDGE
	#define log0()
	#define log1(x) {cout<<" ";cout.width(5);cout<<(x);}
	#define log2(x,y) {log1(x)log1(y)}
	#define log3(x,y,z) {log2(x,y)log1(z)}
	#define logset(x) for(auto i : x) log1(i) //std::size()
	#define logarr1(x,fir) for(auto _7 = begin(x),_6=next(begin(x),fir);_7!=_6;++_7) log1(*_7)
	#define logarr2(x,fir,sec) for(auto _8=begin(x),_9=next(begin(x),fir);_8!=_9;++_8){ logarr1((*_8),sec)log()}
	#define log(...) {cout<<#__VA_ARGS__<<" ";GET_MACRO(_0,##__VA_ARGS__,log3,log2,log1,log0)(__VA_ARGS__);cout<<endl;}
	#define loga(...)  {cout<<#__VA_ARGS__;log()GET_MACRO(""##__VA_ARGS__,UNUSED,logarr2,logarr1,logset)(__VA_ARGS__)log()}
#endif // ONLINE_JUDGE

// template<class T> T gcd(T a, T b){if(!b)return a;return gcd(b,a%b);}
#define gcd __gcd
#define lcm(a,b) ((a)/gcd(a,b)*(b))
inline ll powmod(ll a,ll b,ll mod) {ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
#include<queue>
#define PI 3.14159265358979 //M_PI
const int maxn=1e5+10;

int m,n,k,T,a,b;
queue<int> q;
int lastNum;
int main(){

	in(n);
	in(a,b);
	int mula=1;
	for(int i=2;i*i<=a;i++){
		if(a%i==0){
			mula*=i;
			while(a%i==0) a/=i;
		}
	}
	int mulb=1;
	for(int i=2;i*i<=b;i++){
		if(b%i==0){
			mulb*=i;
			while(b%i==0) b/=i;
		}
	}
	if(mula!=1)
		q.push(mula);
	if(mulb!=1&&mula!=mulb)
		q.push(mulb);
	lastNum=2;
	rep(n-1){
		in(a,b);
		rep(i,q.size()){
			int now=q.front();
			int ga=gcd(a,now);
			int gb=gcd(b,now);
			if(ga==now||gb==now)
				continue;
			q.pop();
			// log(ga,gb)
			if(ga==1){

			}else{
				q.push(ga);
			}
			if(gb==1){

			}else{
				if(gb!=ga) q.push(gb);
			}
		}
	}
	if(n==1){
		put(a);
	}else{
		if(q.size()==0){
		put("-1");
		}else{
			put(q.front());
		}
	}
	
	// log(q.size())

}