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

using ll=long long;
struct Person{
    ll h,p;
};
bool operator<(Person lhs,Person rhs){
    return lhs.h+lhs.p<rhs.h+rhs.p;
}
const ll INF=1e16;

int main(){
    int n;
    cin>>n;
    vector<Person> hp(n);
    for(int i=0;i<n;i++) cin>>hp[i].h>>hp[i].p;
    sort(hp.begin(),hp.end());
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,INF));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            if(dp[i][j]<=hp[i].h) dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+hp[i].p);
            dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
        }
    }
    int res=-1;
    for(int i=0;i<=n;i++){
        if(dp[n][i]<INF) res=i;
    }
    cout<<res<<endl;
    return 0;
}