#include <iostream>
#include <bits/stdc++.h>
#include<string>
using namespace std;
#define boost ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

long long n,m;
string s,st;
std::vector<pair<long long,long long>> a,b;
void get_values()
{
    long long x,y;
    std::cin >> n;
    for(int i=0;i<n;i++)
    {
        std::cin >> x >> y;
        a.push_back({x,i+1});
        b.push_back({y,i+1});
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    //std::cin >> s;
    //n=s.length();
}

void solve()
{
    long long i,j,t,ans=0,x,y,xp,yp;
    x=a[0].first;y=b[0].first;
    xp=a[0].second;yp=b[0].second;
    if(xp!=yp)
        std::cout << max(y,x) << std::endl;
    else 
    {
        long long x1,y1;
        x1=a[1].first;y1=b[1].first;
        ans=x+y;
        ans=min(ans,max(x1,y));
        ans=min(ans,max(x,y1));
        std::cout << ans << std::endl;
    }
}

int main() {
    boost;
    get_values();
    solve();
    return 0;
}
/*
ID: Λινδα
LANG: C++
TASK: abc194a
*/
#include <stdio.h>
#include <algorithm>
using namespace::std;
int read(){char c=getchar();int t=0,f=1;while(c<'0'||c>'9'){if(c=='-'){f=-1;}c=getchar();}while(c>='0'&&c<='9'){t=(t<<1)+(t<<3)+(c^48);c=getchar();}return t*f;}
void write(int x){char ch[50];int l=0;if(x<0){putchar('-');x=-x;}do{ch[l++]=x%10+'0';x=x/10;}while(x);while(l){putchar(ch[--l]);}}
struct wrkr
{
	int id,tm;
};
bool cmpr(wrkr x,wrkr y)
{
	return x.tm<y.tm;
}
int main()
{
//	freopen("main.in","r",stdin);
//	freopen("main.out","w",stdout);
//	freopen("main.err","w",stderr);
	int i,n=read();
	wrkr a[1004],b[1004];
	for(i=0;i!=n;++i)
	{
		a[i].tm=read();
		a[i].id=i;
		b[i].tm=read();
		b[i].id=i;
	}
	sort(a,a+n,cmpr);
	sort(b,b+n,cmpr);
	if(a[0].id==b[0].id)
	{
		write(min(a[0].tm+b[0].tm,min(max(a[0].tm,b[1].tm),max(a[1].tm,b[0].tm))));
	}
	else
	{
		write(max(a[0].tm,b[0].tm));
	}
	putchar('\n');
//	fclose(stdin);
//	fclose(stdout);
//	fclose(stderr);
	return 0;
}