#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

int n;
int vo[10000], to[10000], v[10000], t[10000];
int idx[10000];
bool dp[20001] = {true};

bool cmp(int x, int y) {return to[x] < to[y];}

int main() {
    scanf("%d", &n);
    rep(i, n) {
        scanf("%d%d", vo+i, to+i);
    }
    rep(i, n) idx[i] = i;
    sort(idx, idx + n, cmp);
    rep(i, n) v[i] = vo[idx[i]], t[i] = to[idx[i]];
    rep(i, n) rrep(j, t[i]) dp[j + v[i]] |= dp[j];
    rrep(i, 20001) if (dp[i]) {
        cout << i << endl;
        return 0;
    }
}