// Problem : D - Zabuton
// Contest : AtCoder - CODE FESTIVAL 2017 Final
// URL : https://cf17-final.contest.atcoder.jp/tasks/cf17_final_d
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define infl 1e18+5
#define mninfl -1e18-5
#define Mod 1000000007
#define newmod  998244353
int ah=911382323;
int bh=972663749;
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const long double pi=acos(-1);
//looping
#define int long long
#define For(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' ';  cout<<endl
#define pv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";  cout<<endl
#define pm(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<a[i][j]<<" ";cout<<endl;}cout<<endl
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;
#define deb2(x,y)  cerr << #x << " = " << x <<"   "<< #y << " = " << y << endl;
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define all(v) (v).begin(),(v).end()
int dx[8]={1,-1,0,0,1,1,-1,-1};
int dy[8]={0,0,1,-1,1,-1,1,-1};
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef vector < pair <int, int> > vpii;
typedef pair<int,int>  pii;
/*/----------------------------Code begins----------------------------------/*/
bool comp(pii a ,pii b){
	return a.F+a.S<b.F+b.S;
}
int32_t main(){
fio;
int n;
cin>>n;
vector<pair<int,int> > v(n);
For(i,0,n)
cin>>v[i].F>>v[i].S;
sort(all(v),comp);
int dp[n+1][n+1];
memset(dp,-1,sizeof(dp));

//dp[i][j]=min(dp[i-1][j],dp[i-1][j-1]+p[i]);
for(int i=0;i<=n;i++)
{
	dp[i][0]=0;
}
int mx=mninf;
for(int i=1;i<=n;i++){
	for(int j=1;j<=i;j++){
	if(dp[i-1][j]!=-1){
		dp[i][j]=dp[i-1][j];
		if(dp[i-1][j-1]!=-1&&dp[i-1][j-1]<=v[i-1].F)
		{dp[i][j]=min(dp[i][j],dp[i-1][j-1]+v[i-1].S);
		mx=max(mx,j);}
	}
	else {
		if(dp[i-1][j-1]!=-1&&dp[i-1][j-1]<=v[i-1].F)
		{dp[i][j]=dp[i-1][j-1]+v[i-1].S;
		mx=max(mx,j);}
	}
	
	}
}
cl(mx);

}




























Measured memory_bytes: 195712