#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;

const int N=5005;
const ll inf=(ll)1e15;

struct node{
	ll h,p;
}a[N];
int n,ans;
ll dp[N][N];

bool cmp(node a,node b){
	return a.h+a.p<b.h+b.p;
}

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d%d",&a[i].h,&a[i].p);
	sort(a+1,a+1+n,cmp);
	for (i=0;i<=n;i++)
		for (j=0;j<=n;j++) dp[i][j]=inf;
	dp[0][0]=0;
	for (i=1;i<=n;i++)
		for (j=0;j<i;j++) if (dp[i-1][j]<inf){
			dp[i][j]=min(dp[i][j],dp[i-1][j]);
			if (a[i].h>=dp[i-1][j]) dp[i][j+1]=min(dp[i][j+1],dp[i-1][j]+a[i].p);
		}
	for (i=1;i<=n;i++) if (dp[n][i]<inf) ans=i;
	printf("%d\n",ans);
	return 0;
}