#include<bits/stdc++.h>
using namespace std;
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
#define pii pair<int,int>
#define fi first
#define se second

const int maxn=1e6+5;
int n,cnt,ret;
pii A[maxn];
map<int,int> dd;

bool check(int val){
    map<int,int> mem;
    int cnt=0;
    forinc(i,1,n){
        if(A[i].fi>val) return 0;
        if(A[i].fi<=val&&!mem[A[i].fi]){
            cnt++;
            mem[A[i].fi]=1;
        }
        if(A[i].se<=val&&!mem[A[i].se]){
            cnt++;
            mem[A[i].se]=1;
        }
    }
    return cnt>=n;
}

main(){
  //  freopen("A.inp","r",stdin);
    ios_base::sync_with_stdio(false);
    cin>>n;
    forinc(i,1,n){
        cin>>A[i].fi>>A[i].se;
        if(!dd[A[i].fi]) cnt++,dd[A[i].fi]++;
        if(!dd[A[i].se]) cnt++,dd[A[i].se]++;
    }
    if(cnt<n) return cout<<-1,0;
    int L=1,R=1e9;
    while(L<=R){
        int mid=(L+R)/2;
        if(check(mid)) ret=mid,R=mid-1;
        else L=mid+1;
    }
    cout<<(ret==0?-1:ret);
}

		 	  	 		 	 		 			    		    		