#include <bits/stdc++.h>

using namespace std;


typedef long long ll;

const int M = 1e9+7 ;


int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n ; 
    cin >> n ; 

    vector<pair<ll,ll>> A(n);  
    for(int i = 0 ; i < n ; ++i){
        cin >> A[i].first >> A[i].second ; 
    }

    auto comp = [&](pair<ll,ll>& a,  pair<ll,ll>& b){
        return a.first + a.second < b.first + b.second ;
    };

    sort(A.begin(),A.end(),comp); 


    vector<vector<ll>> dp (n+1 , vector<ll> (n + 1, 1e14)); 

    dp[0][0] = 0 ;

    for(int i = 1 ; i <= n ; ++i){
        for(int j = 0 ; j <= n ; ++j){
            if (j == 0){
                dp[i][j] = min(dp[i][j] , dp[i-1][j]) ; 
                continue ;
            }
            
            dp[i][j] = dp[i-1][j]; 
            
            // if(i == 1 && j == 1){
            //     cout <<"&&&&&&&&&&&&&&&77"<<"\n";
            //     cout << dp[i-1][j] << "\n";
            //     cout << dp[i-1][j-1] << "\n";
            //     cout <<A[i-1].first <<" , "<< A[i-1].second << "\n"; 
            //     cout <<"%%%%%%%%%%%%%%%%%%"<<"\n";
            // }

            if(A[i-1].first >=  dp[i-1][j-1]){
                dp[i][j] = min (dp[i][j], A[i-1].second + dp[i-1][j-1] ); 
            }


        }
        

    }

    // cout <<"dp array :: "<< "\n";

    // for(int i = 1 ; i <= n ;++i){
    //     for(int j = 1 ; j <= n ;++j){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << "\n";
    // }
    for(int j = n ; j >= 0 ;--j){
        if (dp[n][j] != 1e14){
            cout <<  j << "\n"; 
            break; 
        }
    }

    
  
    return 0;
}


#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
//#define MOD (998244353)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");

vii v;
int n,dp[5000][5001];

int f(int i,int k){// f(i,j) min price when j items taken and i items included
    if(k<0)return INF;
    if(i==-1){
        if(k>0)return INF;
        return 0;
    }
    
    int &ans=dp[i][k];
    if(ans!=-1)return ans;
    
    ans=INF;
    int picheka=f(i-1,k-1);
    if(picheka<=v[i].first)ans=min(ans,picheka+v[i].second);
    ans=min(ans,f(i-1,k));
    
    return ans;
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>n;
    v=vii(n);cin>>v;
    sort(all(v),[](const pii &a,const pii &b){return a.first+a.second<b.first+b.second;});
    
    for(int i=n;i>=0;i--){
        if(f(n-1,i)!=INF){
            cout<<i;
            return 0;
        }
    }
}