#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair<int, int> P;
const int INF = 1e15;

int dp[5010], nxt[5010];

signed main(){
    int n;
    cin >> n;
    vector<int> h(n), p(n);
    vector<P> d(n); 
    for(int i = 0; i < n; i++){
        cin >> h[i] >> p[i];
        d[i] = {h[i] + p[i], i};
    }
    sort(d.begin(), d.end());
    for(int i = 0; i <= n; i++) dp[i] = INF;
    dp[0] = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j <= n; j++) nxt[j] = dp[j];
        for(int j = 0; j < n; j++){
            if(dp[j] == INF) continue;
            int id = d[i].second;
            if(dp[j] <= h[id]){
                nxt[j + 1] = min(nxt[j + 1], dp[j] + p[id]);
            }
        }
        swap(dp, nxt);
    }
    int ans = 0;
    for(int i = 0; i <= n; i++){
        if(dp[i] != INF) ans = i;
    }
    cout << ans << endl;
}