#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int dp[100001], dp2[100001];

int main() {
    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;

        for (int j = 0; j < 100001; j++) {
            int t = dp[j] + b;
            if (j - a >= 0) t = min(t, dp[j - a]);
            dp2[j] = t;
        }
        for (int j = 0; j < 100001; j++) {
            dp[j] = dp2[j];
        }
    }

    int r = 1 << 30;
    for (int j = 0; j < 100001; j++) {
        r = min(r, max(j, dp[j]));
    }

    cout << r << endl;

    return 0;
}