#include<bits/stdc++.h>

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define Bs binary_search
#define In insert
#define Mp make_pair
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second

const int mx1 = 20;
const int mx2 = 505;
const int mx3 = 1005;
const int mx4 = 30005;
const int mx5 = 100005;
const int mx6 = 1000005;

typedef vector<int> Vi;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vi> VVi;
typedef pair<int, int> Pii;
typedef pair<DD, DD> Pdd;
typedef vector<Pii> Vpi;
typedef vector<Pdd> Vpd;
typedef queue<int> Qi;
typedef stack<int> Si;
typedef deque<int> Di;

int _toggle(int N, int pos) {return N = N ^ (1 << pos);}
int _set(int N, int pos) {return N = N | (1 << pos);}
int _reset(int N, int pos) {return N = N & ~(1 << pos);}
bool _check(int N, int pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

int dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
int dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///******************************************************///

int n, a[mx3], b[mx3];

void solve()
{
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i] >> b[i];
    }
    int ans = 1e9;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(i == j){
                ans = min(ans, a[i] + b[j]);
            }
            else{
                ans = min(ans, max(a[i], b[j]));
            }
        }
    }
    cout << ans << '\n';
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    fast;
    int tc = 1;
    //cin >> tc;
    while(tc--){
        solve();
    }
}


#include "bits/stdc++.h"
using namespace std;
#define mod 1000000007
#define pie  3.14159265
#define ll long long int
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define vi vector<int>
#define vlli vector<ll>
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fv(i,a) for(auto i:a)
#define sz(a) int((a).size())
#define all(c) (c).begin(),(c).end()
#define frv(i,c) for(auto i = c.begin(); i != c.end(); i++)
 
void solve()
{
	ll n;
	cin >> n;
	vi a(n);
	ll s = 0;
	fr(i, 0, n)
	{
		cin >> a[i];
		s += a[i];
	}
	vi dp(s + 1, 0);
	dp[0] = 1;
	ll ans = 1e9;
	fr (i, 0, n)
	{
		for (ll j = s - a[i]; j >= 0; j--)
		{
			if (dp[j] == 1)
			{
				dp[j + a[i]] = 1;
				ll x = s - (j + a[i]);
				ans = min(ans, max(x, j + a[i]));
			}
		}
	}
	cout << ans << endl;
 
 
}
 
int main() {
	solve();
	return 0;
}