#include <bits/stdc++.h>
using namespace std;
long long n,f[5005];
struct eming
{
	long long a,b;
};
eming e[5005];
long long cmp(eming x,eming y)
{
	return (x.a+x.b<y.a+y.b)?1:0;
}
int main()
{
	scanf("%lld",&n);
	for(long long i=1;i<=n;i++)
	{
		f[i]=99999999999;
		scanf("%lld %lld",&e[i].a,&e[i].b);
	}
	sort(e+1,e+n+1,cmp);
	for(long long i=1;i<=n;i++)
	{
		for(long long j=n;j>=1;j--)
		{
			if(f[j]>f[j-1]+e[i].b&&e[i].a>=f[j-1])
			{
				f[j]=f[j-1]+e[i].b;
			}
		}
	}
	for(long long i=n;i>=0;i--)
	{
		if(f[i]<9999999999)
		{
			printf("%lld\n",i);
			return 0;
		}
	}
	return 0;
}