#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define pi pair<lli,lli>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for(lli i=a;i<b;i++)
#define all(x) x.begin(), x.end()
const lli inf=10000000000000000;
lli mod = 1e9+7;
//const long double pi = 3.14159265358979323846264338;
 
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
        // #ifndef ONLINE_JUDGE 
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
        // #endif
        int t=1;
       // cin>>t;    
while(t--) {
	lli n;
	cin>>n;
	vector <pi> a(n),b(n);

	FOR(i,0,n){
		cin>>a[i].fi>>a[i].se;
		b[i].fi = a[i].se;
		b[i].se = a[i].fi;
	}
	sort(all(a));sort(all(b));
	lli m = inf;
	if(a[0].se==b[0].fi){
		m = min(m,a[0].fi+a[0].se);
		m = min(m,max(a[0].fi,b[1].fi));
		m = min(m,max(a[1].fi,b[0].fi));
	}
	else{
		m = min(m,max(a[0].fi,b[0].fi));
	}
	cout<<m<<endl;
            
}
}
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> veca(n);
  vector<int> vecb(n);
  int cost = 1000000;
  int costt = 1000000;
  for (int i = 0; i < n; i++) {
    cin >> veca.at(i) >> vecb.at(i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j) cost = min(cost, max(veca.at(i), vecb.at(j)));
      if (i == j) costt = min(costt, veca.at(i) + vecb.at(j));
      }
    }
  int ans = min(cost, costt);
  cout << ans;
}