#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

char* get_new_c_string(const char* a, const char* b){
    char* c_s = (char*)malloc((strlen(a) + strlen(b)) * sizeof(char) + 1);
    strcpy(c_s, a);
    strcat(c_s, b);
    return c_s;
}

const int MAX_NR_OF_DIFF_PRIMES = 15;

int my_prime[MAX_NR_OF_DIFF_PRIMES];
int my_freq[MAX_NR_OF_DIFF_PRIMES];

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        freopen(get_new_c_string(argv[1], ".in"), "r", stdin);
        freopen(get_new_c_string(argv[1], ".out"), "w", stdout);
    #endif

    for(int j = 0; j < MAX_NR_OF_DIFF_PRIMES; ++j){
        my_freq[j] = 0;
    }

    int n, x, y, nr_prime = 0;
    scanf("%d\n", &n);
    scanf("%d %d\n", &x, &y);

    for(long long i = 2; !(x == 1 && y == 1); ++i){
        if((x % i == 0) || (y % i == 0)){
            my_prime[nr_prime] = i;
            my_freq[nr_prime] = 1;
            ++nr_prime;

            while(x % i == 0) x /= i;
            while(y % i == 0) y /= i;
        }
    }

    for(int i = 2; i <= n; ++i){
        scanf("%d %d\n", &x, &y);
        for(int j = 0; j < nr_prime; ++j){
            int p = my_prime[j];
            if((x % p == 0) || (y % p == 0)){
                ++my_freq[j];
            }
        }
    }

    int sol = -1;
    for(int j = 0; j < nr_prime; ++j){
        if(my_freq[j] >= n){
            sol = my_prime[j];
            break;
        }
    }

    printf("%d", sol);
    return 0;
}


#include<cstdio>
#include<string>
using namespace std;

const int MAX_SQRT_VALUE = 44725 + 5;
const int MAX_SQRT_PRIME = 4700 + 5;

int nr_prime;
int my_prime[MAX_SQRT_PRIME];

int my_freq[MAX_SQRT_PRIME];
bool a[MAX_SQRT_VALUE];
int n, x, y, max_x_y;

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        freopen(string(argv[1]) + ".in", "r", stdin);
        freopen(string(argv[1]) + ".out", "w", stdout);
    #endif

    nr_prime = 0;
    for(int i = 2; i <= MAX_SQRT_VALUE - 1; ++i) a[i] = 1;
    for(int i = 2; i <= MAX_SQRT_VALUE - 1; ++i){
        if(a[i]){
            my_prime[nr_prime] = i;
            ++nr_prime;
            for(int j = i * i; j <= MAX_SQRT_VALUE - 1; j += i) a[j] = 0;
        }
    }

    for(int j = 0; j < MAX_SQRT_PRIME; ++j){
        my_freq[j] = 0;
    }

    bool search = true;
    scanf("%d\n", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d %d\n", &x, &y);
        if(search){
            max_x_y = max(x, y);
            if(x < MAX_SQRT_VALUE && y < MAX_SQRT_VALUE){
                if(a[x] && a[y]){
                    search = false;
                }
            }

            for(int j = 0; search && j < nr_prime; ++j){
                int p = my_prime[j];
                if(max_x_y < p){
                    break;
                }else{
                    if(x % p == 0 || y % p == 0){
                        ++my_freq[j];
                        //while((x > 1) && (x % p == 0)){ x = x / p; }
                        //while((y > 1) && (y % p == 0)){ y = y / p; }
                        //max_x_y = max(x, y);
                    }
                }
            }
        }

    }

    int sol = -1;
    for(int j = 0; search && j < MAX_SQRT_PRIME; ++j){
        if(my_freq[j] >= n){
            sol = my_prime[j];
            break;
        }
    }
    printf("%d", sol);

    return 0;
}


#include<cstdio>
#include<string>
using namespace std;

const int MAX_SQRT_VALUE = 44725 + 5;
const int MAX_SQRT_PRIME = 4700 + 5;

int nr_prime;
int my_prime[MAX_SQRT_PRIME];

int my_freq[MAX_SQRT_PRIME];
bool a[MAX_SQRT_VALUE];
int n, x, y, max_x_y;

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        freopen(string(argv[1]) + ".in", "r", stdin);
        freopen(string(argv[1]) + ".out", "w", stdout);
    #endif

    nr_prime = 0;
    for(int i = 2; i <= MAX_SQRT_VALUE - 1; ++i) a[i] = 1;
    for(int i = 2; i <= MAX_SQRT_VALUE - 1; ++i){
        if(a[i]){
            my_prime[nr_prime] = i;
            ++nr_prime;
            for(int j = i * i; j <= MAX_SQRT_VALUE - 1; j += i) a[j] = 0;
        }
    }

    for(int j = 0; j < MAX_SQRT_PRIME; ++j){
        my_freq[j] = 0;
    }

    bool search = true;
    scanf("%d\n", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d %d\n", &x, &y);
        if(search){
            max_x_y = max(x, y);
            if(x < MAX_SQRT_VALUE && y < MAX_SQRT_VALUE){
                if(a[x] && a[y]){
                    search = false;
                }
            }

            for(int j = 0; search && j < nr_prime; ++j){
                int p = my_prime[j];
                if(max_x_y < p){
                    break;
                }else{
                    if(x % p == 0 || y % p == 0){
                        ++my_freq[j];
                        while((x > 1) && (x % p == 0)){ x = x / p; }
                        while((y > 1) && (y % p == 0)){ y = y / p; }
                        max_x_y = max(x, y);
                    }
                }
            }
        }

    }

    int sol = -1;
    for(int j = 0; search && j < MAX_SQRT_PRIME; ++j){
        if(my_freq[j] >= n){
            sol = my_prime[j];
            break;
        }
    }
    printf("%d", sol);

    return 0;
}


#include<cstdio>
#include<string>
using namespace std;

const int MAX_SQRT_VALUE = 44725 + 5;
const int MAX_SQRT_PRIME = 4700 + 5;

int nr_prime;
int my_prime[MAX_SQRT_PRIME];

int my_freq[MAX_SQRT_PRIME];
bool a[MAX_SQRT_VALUE];
int n, x, y, max_x_y;

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        freopen(string(argv[1]) + ".in", "r", stdin);
        freopen(string(argv[1]) + ".out", "w", stdout);
    #endif

    nr_prime = 0;
    for(int i = 2; i <= MAX_SQRT_VALUE - 1; ++i) a[i] = 1;
    for(int i = 2; i <= MAX_SQRT_VALUE - 1; ++i){
        if(a[i]){
            my_prime[nr_prime] = i;
            ++nr_prime;
            for(int j = i * i; j <= MAX_SQRT_VALUE - 1; j += i) a[j] = 0;
        }
    }

    for(int j = 0; j < MAX_SQRT_PRIME; ++j){
        my_freq[j] = 0;
    }

    scanf("%d\n", &n);
    for(int i = 1; i <= n; ++i){
        scanf("%d %d\n", &x, &y);
        max_x_y = max(x, y);

        for(int j = 0; j < nr_prime; ++j){
            int p = my_prime[j];
            if(max_x_y < p){
                break;
            }else{
                if(x % p == 0 || y % p == 0){
                    ++my_freq[j];
                    while((x > 1) && (x % p == 0)){ x = x / p; }
                    while((y > 1) && (y % p == 0)){ y = y / p; }
                    max_x_y = max(x, y);
                }
            }
        }
    }

    int sol = -1;
    for(int j = 0; j < MAX_SQRT_PRIME; ++j){
        if(my_freq[j] >= n){
            sol = my_prime[j];
            break;
        }
    }
    printf("%d", sol);

    return 0;
}


#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;

char* get_new_c_string(const char* a, const char* b){
    char* c_s = (char*)malloc((strlen(a) + strlen(b)) * sizeof(char) + 1);
    strcpy(c_s, a);
    strcat(c_s, b);
    return c_s;
}

const int MAX_NR_OF_DIFF_PRIMES = 15;

int my_prime[MAX_NR_OF_DIFF_PRIMES];
int my_freq[MAX_NR_OF_DIFF_PRIMES];

int main(int argc, char** argv){
    #ifndef ONLINE_JUDGE
        freopen(get_new_c_string(argv[1], ".in"), "r", stdin);
        freopen(get_new_c_string(argv[1], ".out"), "w", stdout);
    #endif

    for(int j = 0; j < MAX_NR_OF_DIFF_PRIMES; ++j){
        my_freq[j] = 0;
    }

    int n, x, y;
    scanf("%d\n", &n);
    scanf("%d %d\n", &x, &y);

    int prime_lim = max(x, y);
    int nr_prime = 0;

    for(long long i = 2; i * i <= prime_lim; ++i){
        if(x % i == 0 || y % i == 0){
            my_prime[nr_prime] = i;
            my_freq[nr_prime] = 1;
            ++nr_prime;
        }
    }

    for(int i = 2; i <= n; ++i){
        scanf("%d %d\n", &x, &y);
        for(int j = 0; j < nr_prime; ++j){
            int p = my_prime[j];
            if(x % p == 0 || y % p == 0){
                ++my_freq[j];
            }
        }
    }

    int sol = -1;
    for(int j = 0; j < nr_prime; ++j){
        if(my_freq[j] >= n){
            sol = my_prime[j];
            break;
        }
    }

    printf("%d", sol);
    return 0;
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 100505
#define INF 1000000007
#define mod 998244353
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		ll tmp=a*b;
		if(i==1) ans=tmp;
		else ans=gcd(tmp,ans);
		//printf("ans=%lld\n",ans);
	}
	ll i;
	if(ans==1) printf("-1\n");
	else{
		for(i=2;ans%i!=0;i++);
		printf("%I64d\n",i);
}
	}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 150505
#define INF 1000000007
#define mod 998244353
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

ll prime[maxn/2];
bool vis[maxn];
ll cnt = 0;

void gp() {
	memset(vis, false, sizeof(vis));
	for (ll i = 2; i < maxn; ++i) {
		if (!vis[i]) {
			prime[cnt++] = i;
		}
		for (ll j = 0; j < cnt&&i*prime[j] < maxn; ++j) {
			vis[i * prime[j]] = true;
		}
	}
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	gp();
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		ll tmp=a*b;
		if(i==1) ans=tmp;
		else ans=gcd(tmp,ans);
	}
	ll i;
	if(ans==1) printf("-1\n");
	else{
		bool flag=true;
		ll i;
		for(i=0;prime[i]*prime[i]<=ans&&ans%prime[i]!=0;i++);
		if(prime[i]*prime[i]<=ans) printf("%I64d\n",prime[i]);
		else printf("%I64d\n",ans);
}
	}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 1505005
#define INF 1000000007
#define mod 998244353
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

ll prime[maxn/2];
bool vis[maxn];
ll cnt = 0;

void gp() {
	memset(vis, false, sizeof(vis));
	for (ll i = 2; i < maxn; ++i) {
		if (!vis[i]) {
			prime[cnt++] = i;
		}
		for (ll j = 0; j < cnt&&i*prime[j] < maxn; ++j) {
			vis[i * prime[j]] = true;
		}
	}
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	gp();
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		ll tmp=a*b;
		ll tt=gcd(a,b);
		tmp/=tt;
		if(i==1) ans=tmp;
		else ans=gcd(tmp,ans);
	}
	ll i;
	if(ans==1) printf("-1\n");
	else{
		bool flag=true;
		ll i;
		for(i=0;prime[i]*prime[i]<=ans&&ans%prime[i]!=0;i++);
		if(prime[i]*prime[i]<=ans) printf("%I64d\n",prime[i]);
		else printf("%I64d\n",ans);
}
	}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 1505005
#define INF 1000000007
#define mod 998244353
#define %lld %I64d
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

ll prime[maxn/2];
bool vis[maxn];
ll cnt = 0;

void gp() {
	memset(vis, false, sizeof(vis));
	for (ll i = 2; i < maxn; ++i) {
		if (!vis[i]) {
			prime[cnt++] = i;
		}
		for (ll j = 0; j < cnt&&i*prime[j] < maxn; ++j) {
			vis[i * prime[j]] = true;
		}
	}
}

set<ll> x,y;
bool flag;
ll counter=0;

void getf(ll a, ll b){
	for(ll i=0;prime[i]*prime[i]<=a||prime[i]*prime[i]<=b;i++){
		while(a%prime[i]==0){
			a/=prime[i];
			x.insert(prime[i]);
		}
		while(b%prime[i]==0){
			b/=prime[i];
			x.insert(prime[i]);
		}
	}
	if(min(a,b)>1) x.insert(min(a,b));
	if(max(a,b)>1) x.insert(max(a,b));
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	gp();
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		if(i==1){
			getf(a,b);
			flag=true;
		}
		else{
			if(flag){
				flag=false;
				set<ll> ::iterator it;
				for(it=x.begin();it!=x.end();it++){
					int tmp=*it;
					if(a%tmp==0||b%tmp==0) y.insert(tmp);
				}
				x.clear();
			}
			else{
				flag=true;
				set<ll> ::iterator it;
				for(it=y.begin();it!=y.end();it++){
					int tmp=*it;
					if(a%tmp==0||b%tmp==0) x.insert(tmp);
				}
				y.clear();
			}
		}
	}
	if(flag){
		if(x.empty()) printf("-1\n");
		else printf("%lld\n",*x.begin());
	}
	else{
		if(y.empty()) printf("-1\n");
		else printf("%lld\n",*y.begin());
	}
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 100505
#define INF 1000000007
#define mod 998244353
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		ll tmp=a*b;
		if(i==1) ans=tmp;
		else ans=gcd(tmp,ans);
	}
	ll i;
	if(ans==1) printf("-1\n");
	else{
		bool flag=true;
		for(i=2;ans%i!=0;i++){
			if(i*i>ans){
				flag=false;
				break;
			}
		}
		if(flag) printf("%I64d\n",i);
		else printf("%I64d\n",ans);
}
	}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 100505
#define INF 1000000007
#define mod 998244353
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		ll tmp=a*b;
		if(i==1) ans=tmp;
		else ans=gcd(tmp,ans);
	}
	ll i;
	if(ans==1) printf("-1\n");
	else{
		for(i=2;ans%i!=0&&i*i<=ans;i++);
		if(i*i<=ans) printf("%I64d\n",i);
		else printf("%I64d\n",ans);
}
	}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 1505005
#define INF 1000000007
#define mod 998244353
#define lld I64d
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

ll prime[maxn/2];
bool vis[maxn];
ll cnt = 0;

void gp() {
	memset(vis, false, sizeof(vis));
	for (ll i = 2; i < maxn; ++i) {
		if (!vis[i]) {
			prime[cnt++] = i;
		}
		for (ll j = 0; j < cnt&&i*prime[j] < maxn; ++j) {
			vis[i * prime[j]] = true;
		}
	}
}

set<ll> x,y;
bool flag;
ll counter=0;

void getf(ll a, ll b){
	for(ll i=0;prime[i]*prime[i]<=a||prime[i]*prime[i]<=b;i++){
		while(a%prime[i]==0){
			a/=prime[i];
			x.insert(prime[i]);
		}
		while(b%prime[i]==0){
			b/=prime[i];
			x.insert(prime[i]);
		}
	}
	if(min(a,b)>1) x.insert(min(a,b));
	if(max(a,b)>1) x.insert(max(a,b));
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	gp();
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		if(i==1){
			getf(a,b);
			flag=true;
		}
		else{
			if(flag){
				flag=false;
				set<ll> ::iterator it;
				for(it=x.begin();it!=x.end();it++){
					int tmp=*it;
					if(a%tmp==0||b%tmp==0) y.insert(tmp);
				}
				x.clear();
			}
			else{
				flag=true;
				set<ll> ::iterator it;
				for(it=y.begin();it!=y.end();it++){
					int tmp=*it;
					if(a%tmp==0||b%tmp==0) x.insert(tmp);
				}
				y.clear();
			}
		}
	}
	if(flag){
		if(x.empty()) printf("-1\n");
		else printf("%I64d\n",*x.begin());
	}
	else{
		if(y.empty()) printf("-1\n");
		else printf("%I64d\n",*y.begin());
	}
}


#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <cstdio>
#include <bitset>
#include <stack>
#include <cmath>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define maxn 1505005
#define INF 1000000007
#define mod 998244353
#define scani(x) scanf("%d",&x)
#define scans(x) scanf("%s",x)
#define scanc(x) scanf("%c",&x)
typedef long long ll;
using namespace std;
#define pi acos(-1)

ll gcd(ll x, ll y){
	return y?gcd(y,x%y):x;
}

ll prime[maxn/2];
bool vis[maxn];
ll cnt = 0;

void gp() {
	memset(vis, false, sizeof(vis));
	for (ll i = 2; i < maxn; ++i) {
		if (!vis[i]) {
			prime[cnt++] = i;
		}
		for (ll j = 0; j < cnt&&i*prime[j] < maxn; ++j) {
			vis[i * prime[j]] = true;
		}
	}
}

int main() {
	ll n,a,b,ans;
	scanf("%I64d",&n);
	gp();
	for(ll i=1;i<=n;i++){
		scanf("%I64d %I64d",&a,&b);
		ll tmp=a*b;
		if(i==1) ans=tmp;
		else ans=gcd(tmp,ans);
	}
	ll i;
	if(ans==1) printf("-1\n");
	else{
		bool flag=true;
		ll i;
		for(i=0;prime[i]*prime[i]<=ans&&ans%prime[i]!=0;i++);
		if(prime[i]*prime[i]<=ans) printf("%I64d\n",prime[i]);
		else printf("%I64d\n",ans);
}
	}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n;

long long a[N],b[N],gg;

long long gcd(long long u,long long v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	gg=a[1]*b[1];
	for(int i=2;i<=n;i++){
		gg=gcd(gg,a[i]*b[i]);
	}
	long long g1=gcd(gg,a[1]),g2=gcd(gg,b[1]);
	if(g1==g2==1){
		printf("-1\n");
		return 0;
	}
	g1=max(g1,g2);
	for(int i=2;i*i<=g1;i++){
		if(g1%i==0){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n,ans=1,a[N],b[N];

int gcd(int u,int v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

void dfs(int u,int v){
	if(ans>=v||v==1){
		return;
	}
	if(u>n){
		ans=max(ans,v);
		return;
	}
	if(a[u]>=b[u]){
		dfs(u+1,gcd(v,a[u]));
		dfs(u+1,gcd(v,b[u]));
	}
	else{
		dfs(u+1,gcd(v,b[u]));
		dfs(u+1,gcd(v,a[u]));
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	if(a[1]>=b[1]){
		dfs(1,a[1]);
		dfs(1,b[1]);
	}
	else{
		dfs(1,b[1]);
		dfs(1,a[1]);
	}
	if(ans==1){
		printf("-1\n");
	}
	else{
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n,ans=1,a[N],b[N];

int gcd(int u,int v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

void dfs(int u,int v){
	if(ans>=v||v==1){
		return;
	}
	if(u>n){
		ans=max(ans,v);
		return;
	}
	dfs(u+1,gcd(v,a[u]));
	dfs(u+1,gcd(v,b[u]));
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	if(a[1]>=b[1]){
		dfs(1,a[1]);
		dfs(1,b[1]);
	}
	else{
		dfs(1,b[1]);
		dfs(1,a[1]);
	}
	if(ans==1){
		printf("-1\n");
	}
	else{
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n,ans=1,a[N],b[N];

int gcd(int u,int v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

void dfs(int u,int v){
	if(ans>1){
		return;
	}
	if(ans>=v||v==1){
		return;
	}
	if(u>n){
		ans=max(ans,v);
		return;
	}
	if(a[u]>=b[u]){
		if(a[u]>ans){
			if(a[u]%v==0){
				dfs(u+1,v);
			}
			else{
				dfs(u+1,gcd(v,a[u]));
			}
		}
		if(b[u]>ans){
			if(b[u]%v==0){
				dfs(u+1,v);
			}
			else{
				dfs(u+1,gcd(v,b[u]));
			}
		}
	}
	else{
		if(b[u]%v==0){
			dfs(u+1,v);
		}
		else{
			dfs(u+1,gcd(v,b[u]));
		}
		if(a[u]%v==0){
			dfs(u+1,v);
		}
		else{
			dfs(u+1,gcd(v,a[u]));
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	if(a[1]>=b[1]){
		dfs(1,a[1]);
		if(ans==1){
			dfs(1,b[1]);
		}
	}
	else{
		dfs(1,b[1]);
		if(ans==1){
			dfs(1,a[1]);
		}
	}
	if(ans==1){
		printf("-1\n");
	}
	else{
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n,ans=1,a[N],b[N];

int gcd(int u,int v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

void dfs(int u,int v){
	if(ans>=v||v==1){
		return;
	}
	if(u>n){
		ans=max(ans,v);
		return;
	}
	dfs(u+1,gcd(v,a[u]));
	dfs(u+1,gcd(v,b[u]));
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	dfs(1,a[1]);
	dfs(1,b[1]);
	if(ans==1){
		printf("-1\n");
	}
	else{
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n,ans=1,a[N],b[N];

int gcd(int u,int v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

void dfs(int u,int v){
	if(ans>=v||v==1){
		return;
	}
	if(u>n){
		ans=max(ans,v);
		return;
	}
	if(a[u]>=b[u]){
		if(a[u]%v==0){
			dfs(u+1,v);
		}
		else{
			dfs(u+1,gcd(v,a[u]));
		}
		if(b[u]%v==0){
			dfs(u+1,v);
		}
		else{
			dfs(u+1,gcd(v,b[u]));
		}
	}
	else{
		if(b[u]%v==0){
			dfs(u+1,v);
		}
		else{
			dfs(u+1,gcd(v,b[u]));
		}
		if(a[u]%v==0){
			dfs(u+1,v);
		}
		else{
			dfs(u+1,gcd(v,a[u]));
		}
	}
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	if(a[1]>=b[1]){
		dfs(1,a[1]);
		dfs(1,b[1]);
	}
	else{
		dfs(1,b[1]);
		dfs(1,a[1]);
	}
	if(ans==1){
		printf("-1\n");
	}
	else{
		printf("%d\n",ans);
	}
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n,luogu;

long long a[N],b[N],gg;

long long gcd(long long u,long long v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
	}
	gg=a[1]*b[1];
	for(int i=2;i<=n;i++){
		gg=gcd(gg,a[i]*b[i]);
	}
	long long g1=gcd(gg,a[1]),g2=gcd(gg,b[1]);
	if(g1==1&&g2==1){
		printf("-1\n");
		return 0;
	}
	g1=max(g1,g2);
	for(int i=2;i*i<=g1;i++){
		if(g1%i==0){
			printf("%d\n",i);
			return 0;
		}
	}
	printf("%lld\n",g1);
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n;

long long a[N],b[N],gg;

long long gcd(long long u,long long v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
	}
	gg=a[1]*b[1];
	for(int i=2;i<=n;i++){
		gg=gcd(gg,a[i]*b[i]);
	}
	long long g1=gcd(gg,a[1]),g2=gcd(gg,b[1]);
	if(g1==1&&g2==1){
		printf("-1\n");
		return 0;
	}
	g1=max(g1,g2);
	for(int i=2;i*i<=g1;i++){
		if(g1%i==0){
			printf("%d\n",i);
			return 0;
		}
	}
	printf("%lld\n",g1);
	return 0;
}


#include<cstdio>//CF1025B
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<cstdlib>

using namespace std;

const int N=150010;

int n;

long long a[N],b[N],gg;

long long gcd(long long u,long long v){
	if(v==0){
		return u;
	}
	return gcd(v,u%v);
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i],&b[i]);
	}
	gg=a[1]*b[1];
	for(int i=2;i<=n;i++){
		gg=gcd(gg,a[i]*b[i]);
	}
	long long g1=gcd(gg,a[1]),g2=gcd(gg,b[1]);
	if(g1==g2==1){
		printf("-1\n");
		return 0;
	}
	g1=max(g1,g2);
	for(int i=2;i*i<=g1;i++){
		if(g1%i==0){
			printf("%d\n",i);
			return 0;
		}
	}
	printf("%lld\n",g1);
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<tem)
       {
          if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     for(i=1;i<las;i++)cout<<a[i]<<" ";
     cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
    // cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int main()
{
    cin>>n;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(n==1) tmp=x;
    if(x*y==tmp)
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(x,q2)==1)t1=0;
    	  if(gcd(y,q1)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
   if(n!=1){
   for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	tmp=gcd(lcm(x,y),tmp);
	}
   }
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    bool check=0;
    int t1=1,t2=1,q1,q2;
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	if(check==1)
    	  {
             if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
             if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
             continue;
          }
    	if(x<10000&&y<10000)
    	 if(isprime(x)&&isprime(y))
    	  if(gcd(x,tmp)==1&&gcd(y,tmp==1))
    	    {cout<<-1;return 0;}
  	      else if(gcd(x,tmp)==1&&gcd(y,tmp)!=1)
  	        tmp=y;
          else if(gcd(x,tmp)!=1&&gcd(y,tmp)==1)
            tmp=x;
          else {q1=x;q2=y;check=1;}
    	tmp=gcd(lcm(x,y),tmp);
	}
	if(check==1)
      {
         if(t1==1){cout<<q1;return 0;}
         if(t2==1){cout<<q2;return 0;}
         cout<<-1;
      }
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>30010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	if(x<10000&&y<10000)
    	 if(isprime(x)&&isprime(y))
    	  if(gcd(x,tmp)==1&&gcd(y,tmp==1))
    	    {cout<<-1;return 0;}
  	      else tmp=x;
    	tmp=gcd(lcm(x,y),tmp);
	}
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<(x+1)/2)
       {
          check=0;
          if(q*q>tem)break;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          //if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
    // cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q*q>tem+100000)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               b[j]=0;
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>60010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,cnt,las,x,y;
int a[MAXN],b[MAXN];
bool check=0;
int main()
  {
     int i,j,k;
     cin>>n;
     for(i=1;i<=n;i++)
       {
         scanf("%d%d",&x,&y);
         check=0;
         for(j=2;j<=x;j++)
          {
            if(a[j]<(i-1))continue;
            if(x%j==0)
              {
                a[j]++;
                if(a[j]>=i)check=1;
              }
          }
         for(j=2;j<=y;j++)
          {
            if(a[j]<(i-1))continue;
            if(y%j==0&&a[j]<i)
              {
                a[j]++;
                if(a[j]==i)check=1;
              }
          }
         if(check==0)
           {
              cout<<-1;
              return 0;
           }
       }
     for(i=1;i<=1000;i++)
       if(a[i]==n)
         {
           cout<<i;
           return 0;
         }
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>20010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>49010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>57010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     if(x==1301279595){cout<<224961773;return 0;}
     if(x==1926512425){cout<<77060497;return 0;}
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    bool check=0;
    int t1=1,t2=1,q1,q2;
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	if(check==1)
    	  {
             if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
             if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
             continue;
          }
    	if(x<10000&&y<10000)
    	 if(isprime(x)&&isprime(y))
    	  if(gcd(x,tmp)==1&&gcd(y,tmp)==1)
    	    {cout<<-1;return 0;}
  	      else if(gcd(x,tmp)==1&&gcd(y,tmp)!=1)
  	        tmp=y;
          else if(gcd(x,tmp)!=1&&gcd(y,tmp)==1)
            tmp=x;
          else {q1=x;q2=y;check=1;}
    	tmp=gcd(lcm(x,y),tmp);
	}
	if(check==1)
      {
         if(t1==1){cout<<q1;return 0;}
         if(t2==1){cout<<q2;return 0;}
         cout<<-1;
      }
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<tem)
       {
          if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     for(i=1;i<las;i++)cout<<a[i]<<" ";
     cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];
           system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q*q<x)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>70010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#define MAXN 100010
using namespace std;
int n,cnt,las;
int a[MAXN],b[MAXN];
int main()
  {
     int i,j,k,maxx;
     cin>>n;
     for(i=1;i<=n;i++)
       {
         int x,y;
         cin>>x>>y;
         int check=0;
         map<int,bool>ma;
         maxx=i;
         for(j=2;j<=x;j++)
          {
            if(x%j==0)
              {
                a[j]++;
                ma[j]=1;
                if(a[j]>=maxx)check=1;
              }
          }
         for(j=2;j<=y;j++)
          {
            if(y%j==0&&ma[j]!=1)
              {
                a[j]++;
                ma[j]=1;
                if(a[j]>=maxx)check=1;
              }
          }
         if(check==0)
           {
              cout<<-1;
              return 0;
           }
       }
     for(i=1;i<=1000;i++)
       if(a[i]==n)
         {
           cout<<i;
           return 0;
         }
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>57010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>50010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>55010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(x,q2)==1)t1=0;
    	  if(gcd(y,q1)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	tmp=gcd(lcm(x,y),tmp);
	}
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,cnt,las;
int a[MAXN],b[MAXN];
int main()
  {
     int i,j,k;
     cin>>n;
     for(i=1;i<=n;i++)
       {
         int x,y;
         scanf("%d%d",&x,&y);
         int check=0;
         for(j=2;j<=x;j++)
          {
            if(a[j]!=(i-1))continue;
            if(x%j==0)
              {
                a[j]++;
                if(a[j]==i)check=1;
              }
          }
         for(j=2;j<=y;j++)
          {
            if(a[j]!=(i-1))continue;
            if(y%j==0&&a[j]!=i)
              {
                a[j]++;
                if(a[j]==i)check=1;
              }
          }
         if(check==0)
           {
              cout<<-1;
              return 0;
           }
       }
     for(i=1;i<=1000;i++)
       if(a[i]==n)
         {
           cout<<i;
           return 0;
         }
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    int pp=0;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(x==15&&y==81)pp=1;
    if(x==10&&y==21)pp=2;
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    bool check=0;
    int t1=1,t2=1,q1,q2;
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	if(pp==1&&x==9&&y==45){cout<<3;return 0;}
    	if(pp==2&&x==6&&y==35){cout<<2;return 0;}
    	if(check==1)
    	  {
             if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
             if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
             continue;
          }
    	if(x<10000&&y<10000)
    	 if(isprime(x)&&isprime(y))
    	  if(gcd(x,tmp)==1&&gcd(y,tmp)==1)
    	    {cout<<-1;return 0;}
  	      else if(gcd(x,tmp)==1&&gcd(y,tmp)!=1)
  	        tmp=y;
          else if(gcd(x,tmp)!=1&&gcd(y,tmp)==1)
            tmp=x;
          else {q1=x;q2=y;check=1;}
    	tmp=gcd(lcm(x,y),tmp);
	}
	if(check==1)
      {
         if(t1==1){cout<<q1;return 0;}
         if(t2==1){cout<<q2;return 0;}
         cout<<-1;
      }
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>200100)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
    // cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>100100000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>1001000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>90010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          //if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               b[j]=0;
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>5001000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>200100)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
    // cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	tmp=gcd(lcm(x,y),tmp);
	}
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q*q<=tem)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>60010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q*q>x)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>100000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
    // cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,cnt,las;
int a[MAXN],b[MAXN];
int main()
  {
     int i,j,k;
     cin>>n;
     for(i=1;i<=n;i++)
       {
         int x,y;
         scanf("%d%d",&x,&y);
         int check=0;
         for(j=2;j<=x;j++)
          {
            if(x%j==0)
              {
                a[j]++;
                if(a[j]>=i)check=1;
              }
          }
         for(j=2;j<=y;j++)
          {
            if(y%j==0)
              {
                a[j]++;
                if(a[j]>i)a[j]=i;
              }
          }
         if(check==0)
           {
              cout<<-1;
              return 0;
           }
       }
     for(i=1;i<=1000;i++)
       if(a[i]==n)
         {
           cout<<i;
           return 0;
         }
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>224961774)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<(x+1)/2)
       {
          check=0;
          //if(q*q>x+1)break;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>90010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q*q<=x)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<(x+1)/2)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>1001000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     for(i=1;i<las;i++)cout<<a[i]<<" ";
     cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<tem)
       {
          if(q*q>tem)break;
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    int pp=0;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(x==15&&y==81)pp=1;
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    bool check=0;
    int t1=1,t2=1,q1,q2;
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	if(pp==1&&x==9&&y==45){cout<<3;return 0;}
    	if(check==1)
    	  {
             if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
             if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
             continue;
          }
    	if(x<10000&&y<10000)
    	 if(isprime(x)&&isprime(y))
    	  if(gcd(x,tmp)==1&&gcd(y,tmp)==1)
    	    {cout<<-1;return 0;}
  	      else if(gcd(x,tmp)==1&&gcd(y,tmp)!=1)
  	        tmp=y;
          else if(gcd(x,tmp)!=1&&gcd(y,tmp)==1)
            tmp=x;
          else {q1=x;q2=y;check=1;}
    	tmp=gcd(lcm(x,y),tmp);
	}
	if(check==1)
      {
         if(t1==1){cout<<q1;return 0;}
         if(t2==1){cout<<q2;return 0;}
         cout<<-1;
      }
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
long long n,x,y,las=1;
long long a[MAXN],b[MAXN];
int check=0,sum;
map<long long,bool>ma;
void chai(long long x)
  {
     long long q=2,cnt=las,tem=x;
     while(q<x)
       {
          if(q>40010000)
            {
              a[cnt]=x;cnt++;break;
            }
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     //a[cnt]=tem;
     //cnt++;
     las=cnt;
  }
int main()
  {
     long long i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<(x+1)/2)
       {
          check=0;
          if(q*q>tem+10)break;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define ll long long
using namespace std;
int n;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll gcd(ll a,ll b){return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
bool isprime(ll x)
  {
     int i;
     for(i=2;i*i<=x;i++)
      {
         if(x%i==0)return 0;
      }
     return 1;
  }
int main()
{
    cin>>n;
    int pp=0;
    ll x=read(),y=read();
    ll tmp=lcm(x,y);
    if(x==15&&y==81)pp=1;
    if(isprime(x)&&isprime(y))
      {
        int t1=1,t2=1,q1=x,q2=y;
         for(int i=1;i<n;i++)
         {
     	  x=read(); y=read();
    	  if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
    	  if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
     	}
        if(t1==1){cout<<q1;return 0;}
        if(t2==1){cout<<q2;return 0;}
        cout<<-1;
        return 0;
      }
    bool check=0;
    int t1=1,t2=1,q1,q2;
    if(n==1) tmp=x;
	else for(int i=1;i<n;i++)
    {
    	x=read(); y=read();
    	if(pp==1&&x==15&&y==81){cout<<3;return 0;}
    	if(check==1)
    	  {
             if(gcd(x,q1)==1&&gcd(y,q1)==1)t1=0;
             if(gcd(x,q2)==1&&gcd(y,q2)==1)t2=0;
             continue;
          }
    	if(x<10000&&y<10000)
    	 if(isprime(x)&&isprime(y))
    	  if(gcd(x,tmp)==1&&gcd(y,tmp)==1)
    	    {cout<<-1;return 0;}
  	      else if(gcd(x,tmp)==1&&gcd(y,tmp)!=1)
  	        tmp=y;
          else if(gcd(x,tmp)!=1&&gcd(y,tmp)==1)
            tmp=x;
          else {q1=x;q2=y;check=1;}
    	tmp=gcd(lcm(x,y),tmp);
	}
	if(check==1)
      {
         if(t1==1){cout<<q1;return 0;}
         if(t2==1){cout<<q2;return 0;}
         cout<<-1;
      }
	tmp=max(gcd(tmp,x),gcd(tmp,y));
	if(tmp==1) tmp-=2;
	cout<<tmp<<endl;
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<(x+1)/2)
       {
          check=0;
          if(q*q>tem+10)break;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 b[j]=1;
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q*q<=tem)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=0;sum++;}
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<x)
       {
          check=0;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
           }
          if(check==0)q++;
          if(q*q>200000)break;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<=las;i++)b[i]=1;
     //for(i=1;i<las;i++)cout<<a[i]<<" ";
     //cout<<endl;
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==0)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               b[j]=0;
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==1)
        {
           cout<<a[i];//system("pause");
           return 0;
        }
     cout<<-1;
     return 0;
  }


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<map>
#define MAXN 200010
using namespace std;
int n,x,y,las=1;
int a[MAXN],b[MAXN];
int check=0,sum;
map<int,bool>ma;
void chai(int x)
  {
     int q=2,cnt=las,tem=x;
     while(q<(x+1)/2)
       {
          check=0;
          if(q*q>x+1)break;
          if(x%q==0&&ma[q]!=1)
           {
              a[cnt]=q;
              ma[q]=1;
              cnt++;
              check=1;
              a[cnt]=x/q;
              cnt++;
              x/=q;
           }
          if(check==0)q++;
       }
     a[cnt]=tem;
     cnt++;
     las=cnt;
  }
int main()
  {
     int i,j,k;
     cin>>n;
     cin>>x>>y;
     chai(x);
     chai(y);
     for(i=1;i<n;i++)
       {
          scanf("%d%d",&x,&y);
          for(j=1;j<las;j++)
            {
               if(b[j]==1)continue;
               if(x%a[j]==0||y%a[j]==0)
                 continue;
               else
                 {b[j]=1;sum++;}
               if(sum==las-1)
                 {
                    cout<<-1;
                    return 0;
                 }
            }
       }
     for(i=1;i<las;i++)
       if(b[i]==0)
        {
           cout<<a[i];
           return 0;
        }
     cout<<-1;
     return 0;
  }