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

#define ff        first
#define ss        second

typedef pair <int,int>         ii ;

const int N = 5010 ;

set <ii> st ;
ii x [N];

int main() {
    int n ; cin >> n ;
    for ( int i = 0 ; i < n ; ++i ) {
        cin >> x[i].ff >> x[i].ss ;
        st.insert ( {x[i].ff, i} ) ;
    }
    int ans = 0, curH = 0 ;
    while ( st.size() ) {
        vector <ii> posible ;
        for ( auto j:st ) {
            if ( j.ff >= curH ) posible.push_back({x[j.ss].ss, j.ss}) ;
        }
        sort ( posible.begin(), posible.end() ) ;
        auto j = st.begin() ;
        while ( j!=st.end() && (*j).first < curH + x[posible[0].ss].ss ) j = next(j) ;
        int ideal = posible[0].ss ;
        int del = 1 ;
        for ( auto k:posible ) {
            auto h = st.begin() ;
            while ( h!=st.end() && (*h).first < curH + x[k.ss].ss ) h = next(h) ;
            if ( h == j && x[k.ss].ff < curH + x[k.ss].ss ) {
                del = 0 ;
                ideal = k.ss ;
                break ;
            }
        }
        curH += x[ideal].ss ;
        auto k = st.begin() ;
        while ( k != j ) {
            auto nxt = next ( k ) ;
            st.erase (*k) ;
            k = nxt ;
        }
        if ( del ) st.erase ( {x[ideal].ff, ideal} ) ;
        ans ++ ;
    }
    cout << ans << '\n' ;
}
