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

#if LOCAL
    #define debug(args...)     (Debugger()) , args
 		class Debugger {
        public:
        Debugger(const std::string& _separator = ", ") :
        first(true), separator(_separator){}
 		template<typename ObjectType>
        Debugger& operator , (const ObjectType& v)
        {
            if(!first) std::cout << separator;
            std::cout << v;
            first = false;
            return *this;
        }
        ~Debugger() {  std::cout << endl;}
 		private:
        bool first;
        std::string separator;
    };
	 template <typename T1, typename T2>
    inline std::ostream& operator << (std::ostream& os, const std::pair<T1, T2>& p)
    {
        return os << "(" << p.first << ", " << p.second << ")";
    }
 	template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::vector<T>& v)
    {
        bool first = true;
        os << "[";
        for(unsigned int i = 0; i < v.size(); i++)
        {
            if(!first) os << ", ";
            os << v[i];
            first = false;
        }
        return os << "]";
    }
 	template<typename T>
    inline std::ostream &operator << (std::ostream & os,const std::set<T>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::set<T>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
        {
            if(!first) os << ", ";
            os << *ii;
            first = false;
        }
        return os << "]";
    }
	template<typename T1, typename T2>
    inline std::ostream &operator << (std::ostream & os,const std::map<T1, T2>& v)
    {
        bool first = true;
        os << "[";
        for (typename std::map<T1, T2>::const_iterator ii = v.begin(); ii != v.end(); ++ii)
        {
            if(!first)
                os << ", ";
            os << *ii ;
            first = false;
        }
        return os << "]";
    }
 #else
    #define debug(args...)                  // Just strip off all debug tokens
#endif

typedef long long int ll;

#define endl "\n";
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(cont,it) for(decltype((cont).begin()) it = (cont).begin(); it != (cont).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())

const ll mod = 1000000007;
const ll inf = (ll)1e15;
ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = (x*x)%m; if(b % 2) x = (x*a)%m; return x;}

const int N=5111;
vector<pair<ll,ll>> vp;
int n;
ll dp[N][N];
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2)
{
	return (p1.first+p1.second)<(p2.first+p2.second);
}

void solve()
{
	cin >> n;
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin >> x >> y;
		vp.pb(mp(x,y));
	}
	sort(all(vp),cmp);
	for(int i=0;i<N;i++)
	{
		for(int j=0;j<N;j++)
			dp[i][j]=inf;
	}
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(j==0)
			{	dp[i][j]=0;
				continue;
			}
			dp[i][j]=min(dp[i-1][j],vp[i-1].first>=dp[i-1][j-1]?dp[i-1][j-1]+vp[i-1].second:inf);
		}
	}
	int ans=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			if(dp[i][j]!=inf)
				ans=max(ans,j);
		}
	}
	cout << ans << endl;
}

int main()
{
	IOS;
	int t = 1, num = 1;   ///// change this t for number of testcase globally
#ifdef LOCAL
   cin >> t;   ///// change this t for number of testcase locally
#endif
    while (t--) 
    {
        solve();
        debug("\n");
    }
	return 0;
}


Measured memory_bytes: 204544