#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 1000000007
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 2000003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int n,a[mx],b[mx],par[mx];
vector<int>ve;
int find(int a){
//	if(a>=0)cout<<"yo "<<a<<" "<<par[a]<<endl;
	if(a==-1 || a==par[a])return a;
	return par[a]=find(par[a]);
}

bool cek(int mid){
//	debug(mid);
	for(int i=0;i<ve.size();i++)par[i]=i;
	for(int i=1;i<=n;i++){
//		debug(i);
		if(a[i]>mid)return false;
		if(b[i]>mid){
			int x=find(a[i]);
			if(x==-1)return false;
			par[x]=-1;
		}
		else{
			int x=find(a[i]);
			if(ve[mid]==100){
			//	debug(x);
			}
			if(x==-1){
				x=find(b[i]);
				if(x==-1)return false;
		//		debug(x);
				par[x]=-1;
			}
			else{
				if(x==b[i])par[x]=-1;
				else par[x]=find(b[i]);
			}
		}
	}
	return true;
	
}

int main(){
	
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d%d",&a[i],&b[i]),ve.pb(a[i]),ve.pb(b[i]);
	sort(ALL(ve));
	ve.erase(unique(ALL(ve)),ve.end());
	for(int i=1;i<=n;i++){
		a[i]=lower_bound(ALL(ve),a[i])-ve.begin();
		b[i]=lower_bound(ALL(ve),b[i])-ve.begin();
	}
	int lo=0,hi=ve.size()-1,jaw=-1;
	while(lo<=hi){
		int mid=(lo+hi)>>1;
		if(cek(mid)){
			hi=mid-1;
			jaw=mid;
		}
		else lo=mid+1;
	}
	if(jaw==-1){
		cout<<-1;
		return 0;
	}
	cout<<ve[jaw];
}




