#include<bits/stdc++.h>
using namespace std;

struct Participant{
    int h, p;
    bool operator<(const Participant& obj)const{
        if(p != obj.p)return h+p < obj.h+obj.p;
        else return p < obj.p;
    }
};

long long int dp[5003][5003] = {0};

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

    vector<Participant> v;
    v.push_back((Participant){0, 0});
    for(int i=0;i<n;++i){
        int h, p;
        cin >> h >> p;
        v.push_back((Participant){h, p});
    }

    sort(v.begin(), v.end());

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

    for(int i=1;i<=n;++i){
        for(int j=1;j<=i;++j){
            dp[i][j-1] = min(dp[i][j-1], dp[i-1][j-1]);
            if(dp[i-1][j-1] <= v[i].h){
                dp[i][j] = min(dp[i][j], dp[i-1][j-1] + v[i].p);
            }
        }
    }

    int ans = 0;
    for(int i=1;i<=n;++i){
        if(dp[n][i] != LLONG_MAX)ans = i;
    }

    cout << ans << endl;

    return 0;
}
