#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

class Data
{
public:
    int r, w;
    bool operator<(const Data& d) const{
        return r < d.r;
    }
};

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Data> d(n);
        int rSum = 0;
        int wSum = 0;
        for(int i=0; i<n; ++i){
            cin >> d[i].r >> d[i].w;
            rSum += d[i].r;
            wSum += d[i].w;
        }
        sort(d.rbegin(), d.rend());

        if(2 * d[0].r <= rSum){
            cout << (rSum + wSum) << endl;
            continue;
        }

        int t = 2 * d[0].r - rSum;
        vector<bool> dp(t+1, false);
        dp[0] = true;
        for(int i=1; i<n; ++i){
            for(int j=t; j>=d[i].w; --j){
                if(dp[j-d[i].w])
                    dp[j] = true;
            }
        }

        while(!dp[t])
            -- t;

        int ret = d[0].r * 2 + (wSum - t);
        cout << ret << endl;
    }
}