#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <random>
#include <functional>

using namespace std;

#define F first
#define S second
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"; 
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define dbv(a) cerr << #a << ": "; for (auto& xxxx: a) cerr << xxxx << " "; cerr << endl;
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)a.size()
#define pw(n) (1ll << (n))
#define equal equalll
#define less lesss

typedef double dbl;
typedef long long ll;
//const int N = 50;
const int N = 5005;
const int INF = 1.01e9;
typedef vector<int> vi;

struct Item {
    ll p, h;
};


ll dp[N][N];

int fast(vector<Item> a) {
    int n = a.size();
    sort(all(a), [](Item A, Item B) {
                ll sAB = min(A.h, B.h - A.p); 
                ll sBA = min(B.h, A.h - B.p);
                if (sAB > sBA) {
                    return 1;
                }
                return 0;
            });

    memset(dp, 63, sizeof dp);     
    //for (int i = 0; i < n; i++) {
        //db2(a[i].h, a[i].p);
    //}

    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            if (dp[i][j] <= a[i].h) {
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + a[i].p);
            }
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }
    int answer = 0;
    for (int i = 0; i <= n; i++) {
        if (dp[n][i] < 1e15) {
            answer = i;
        }
    }
    //cout << answer << endl;
    return answer;
}



int slow(vector<Item> a) {
    int n = a.size();
    vector<int> perm;
    for (int i = 0; i < n; i++) {
        perm.pb(i);
    } 
    int answer = 0;

    do {
        vector<Item> b(n);
        for (int i = 0; i < n; i++) {
            b[i] = a[perm[i]];
        }

        ll cur = 0;
        int i = 0;
        for (i = 0; i < n; i++) {
            if (b[i].h >= cur) {
                cur += b[i].p;
            }
            else {
                break;
            }
        }
        answer = max(answer, i);
    }
    while (next_permutation(all(perm)));
    return answer;
}

// TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

int main() {
#ifdef HOME 
    assert(freopen("in", "r", stdin));
#endif
    if (1) {
        int n;
        scanf("%d", &n); 
        vector<Item> a(n);
        for (int i = 0; i < n ;i++) {
            scanf("%lld%lld", &a[i].h, &a[i].p);
        }
        cout << fast(a) << endl;
        //cout << slow(a) << endl;
    }
    else {
        for (int tt = 0;; tt++) {
            db(tt);
            int n = rand() % 8 + 1;
            vector<Item> a;
            int C = 100;
            for (int i = 0; i < n; i++) {
                a.pb({rand() % C, rand() % C + 1});
            }
            cout << n << endl;
            for (auto x: a) {
                cout << x.h << " " << x.p << endl;
            }
            auto r1 = fast(a);
            auto r2 = slow(a);
            assert(r1 == r2);
        }        
    }

    







    
#ifdef HOME 
    epr("time = %d ms\n", (int)(clock() * 1000. / CLOCKS_PER_SEC));
#endif
    return 0;
}


Measured memory_bytes: 196224