#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

//#include <bits/stdc++.h>
using namespace std;

typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;

//Loop defines
#define rep(i,n) for(int i=0;i<n;++i)
#define dow(i,n) for(int i=n-1;i>=0;--i)

//Print defines
#define pr(_) cout << _ << endl
#define prln() cout << endl
#define pra(a,n) rep(i,n) cout<<a[i]<<" "; prln()
#define prv(v) rep(i,v.size()) cout<<v[i]<<" "; prln()
#define endl "\n"

//Natural set
#define fill_nat(v,n) rep(i,n) v[i]=i // or use iota
// const ll inf = numeric_limits<ll>::max() / 2;

//Vector
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front

//Data structures
#define heap priority_queue
#define hash_map unordered_map
#define hash_set unordered_set

#define st first
#define nd second

// INT_MAX


// ======[ DEBUG TEMPLATE ]======
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
// ==============================
int boxPyramidN2(vector<pii> boxes) {
    sort(boxes.begin(), boxes.end(), [](pii a, pii b) {
        return a.st + a.nd < b.st + b.nd;
    });
    // deb(boxes);
    int n = boxes.size();
    vector<ll> dp(boxes.size()+1, LLONG_MAX);

    dp[0] = 0;
    for (int i=0; i<n; ++i) {
        for (int j=n-1; j>=0; --j) {
            if (boxes[i].st >= dp[j] && dp[j] + boxes[i].nd < dp[j+1]) {
                dp[j+1] = dp[j] + boxes[i].nd;
            }
        }
    }
    deb(dp);
    cout << endl;
    
    int count = 0;
    for (int i=1; i<=n; ++i) {
        if (dp[i] != LLONG_MAX) count++;
    }

    return count;
}

int boxPyramid(vector<pii> boxes) {
    sort(boxes.begin(), boxes.end(), [](pii a, pii b) {
        return a.st + a.nd < b.st + b.nd;
    });
    // deb(boxes);
    int n = boxes.size();
    vector<ll> dp(boxes.size()+1, LLONG_MAX);

    dp[0] = 0;
    for (int i=0; i<n; ++i) {
        for (int j=n-1; j>=0; --j) {
            if (boxes[i].st >= dp[j] && dp[j] + boxes[i].nd < dp[j+1]) {
                dp[j+1] = dp[j] + boxes[i].nd;
            }
        }
    }
    // deb(dp);
    // cout << endl;
    
    int count = 0;
    for (int i=1; i<=n; ++i) {
        if (dp[i] != LLONG_MAX) count++;
    }

    return count;
}

int main() {
// #ifndef ONLINE_JUDGE 
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout); 
// #endif
    cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);

    int size;
    cin >> size;
    vector<pii> v;
    for (int i=0; i<size; ++i) {
        int str, weight;
        cin >> str >> weight;
        v.push_back(make_pair(str, weight));
    }
    // deb(v);

    // for (int i=0; i<=v.size(); ++i) {
    //     for (int j=0; j<i; ++j) {
    //         dp[]
    //     }
    // }

    cout << boxPyramid(v) << endl;
    return 0;
}


Measured memory_bytes: 384