#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll INF = 100000000000000;

int main()
{
    int n;
    cin >> n;
    P p[1003];
    for(int i = 0; i < n; i++){
        ll w, s;
        cin >> w >> s;
        p[i] = P(w + s, s);
    }
    sort(p, p + n);
    ll dp[1003];
    dp[0] = 0;
    for(int j = 1; j <= n; j++) dp[j] = INF;
    for(int i = 0; i < n; i++){
        ll w = p[i].first - p[i].second, s = p[i].second;
        ll d[1003];
        for(int j = 0; j <= n; j++) d[j] = dp[j];
        for(int j = 1; j <= n; j++){
            if(dp[j - 1] <= s) d[j] = min(d[j], dp[j - 1] + w);
        }
        swap(dp, d);
    }
    for(int j = n; j >= 0; j--){
        if(dp[j] < INF){
            cout << j << endl;
            return 0;
        }
    }
}