#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <vector>
#include <stack>
#include <map>
#define ri register
#define inf 0x7fffffff
#define E (1)
#define mk make_pair
#define int long long
using namespace std; const int N=5010;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar(); return s*w;
}
int n,dp[N]; struct Node{int h,p; }e[N];
inline bool cp(Node x,Node y) { return x.h+x.p<y.h+y.p; }
signed main()
{
	n=read();
	for(ri int i=1;i<=n;i++) e[i].h=read(), e[i].p=read();
	sort(e+1,e+1+n,cp); int res=0;
	for(ri int i=1;i<=n;i++) dp[i]=1e16;
	for(ri int i=1;i<=n;i++)
	{for(ri int j=i;j;j--)if(e[i].h>=dp[j-1])dp[j]=min(dp[j],dp[j-1]+e[i].p);}
	for(ri int i=0;i<=n;i++)if(dp[i]<1e16)res=i; printf("%lld\n",res);
	return 0;
}