#include <iostream>
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
void solve(){
    int n;
    cin>>n;
    vector<pair<int,int>> seq(n);
    for(auto &[h,p] : seq){
        cin>>h>>p;
    }
    sort(seq.begin(), seq.end(), [](const pair<int,int> &x, const pair<int,int> &y){return x.first + x.second < y.first + y.second;});
    ll height = 0;
    const int INF = 2e9 + 7;
    vector<vector<int>> dp(n+1, vector<int>(n+1, INF));
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        int h = seq[i-1].first, p = seq[i-1].second; 
        for(int j=1;j<=n;j++){
            dp[i][j] = dp[i-1][j];
            if(dp[i-1][j-1]<=h){
                dp[i][j] = min(dp[i][j], dp[i-1][j-1] + p);
            }
        }
    }
    for(int i=n;i>=0;--i){
        if(dp[n][i]<INF){
            cout<<i<<"\n";
            return;
        }
    }
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}