// https://cf17-final.contest.atcoder.jp/tasks/cf17_final_d
#include <bits/stdc++.h>

using namespace std;

int n, h, p;
long long dp[5050], tmp[5050];
vector<pair<int, int>> v;

bool cmp(pair<int, int> a, pair<int, int> b) {
    return (a.first + a.second < b.first + b.second);
}

int main() {
    scanf("%d", &n);
    for(int i = 0; i < n; i++) {
        scanf("%d %d", &h, &p);
        v.emplace_back(h, p);
    }
    sort(v.begin(), v.end(), cmp);

    for(int i = 1; i < 5050; i++)
        dp[i] = 10000000000000000LL;

    for(int i = 0; i < n; i++) {
        memcpy(tmp, dp, sizeof dp);
        for(int j = 0; j <= i; j++) {
            if(v[i].first >= tmp[j])
                dp[j+1] = min(dp[j+1], tmp[j] + v[i].second);
        }
    }

    for(int i = n; i >= 0; i--) {
        if(dp[i] < 10000000000000000LL) {
            printf("%d\n", i);
            return 0;
        }
    }
    return 0;
}
