#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define mod 1000000007

int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<pair<ll,ll>> v1,v2;
    for(ll i=0;i<n;i++)
    {
        ll l,r;
        cin>>l>>r;
        v1.push_back({l,i});
        v2.push_back({r,i});
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    if(v1[0].second==v2[0].second)
    {
        ll ans=min(v1[0].first+v2[0].first,min(max(v1[0].first,v2[1].first),max(v1[1].first,v2[0].first)));
        cout<<ans<<endl;
    }
    else
        cout<<max(v1[0].first,v2[0].first)<<endl;
    return 0;       
}
#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }

int main() {
	int n; 
	scanf("%d", &n);
	int a[n][2];
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i][0]);
		scanf("%d", &a[i][1]);
	}
	int ans = 1e9 + 7;
	for(int i = 0; i < n; ++i){
		ans = min(ans, a[i][0] + a[i][1]);
	}
	for(int i = 0; i < n; ++i){
		int val1 = a[i][0];
		int val2 = a[i][1];
		for(int j = 0; j < n; ++j){
			if(i != j) {
				ans = min(ans, max(val1, a[j][1]));
				ans = min(ans, max(val2, a[j][0]));
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}
