#include <bits/stdc++.h>

using namespace std;

const int N = 5 * 1000 + 17;
const int MOD = 2 * 1000 * 1000 * 1000 + 7;

struct item {
    int h, p;
    item() = default;
};

int n;
item a[N];
long long dp[N][N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n; ++i)
        cin >> a[i].h >> a[i].p;

    return true;
}

void solve() {
    sort(a, a + n, [](item a, item b) { return a.h + a.p < b.h + b.p; });

    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= n; ++j)
            dp[i][j] = MOD;

    dp[0][0] = 0;
    dp[0][1] = a[0].p;

    for (int i = 1; i < n; ++i)
        for (int j = 0; j <= i + 1; ++j) {
            dp[i][j] = dp[i - 1][j];

            if (j > 0 && dp[i - 1][j - 1] <= a[i].h)
                dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + a[i].p);
        }

    auto ans = 0;

    for (int i = 0; i <= n; ++i)
        if (dp[n - 1][i] < MOD)
            ans = i;

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}

