#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=10000000000000000ll;

int main()
{
  int n;
  scanf("%d",&n);
  static pair<ll,ll> P[10000];
  for(int i=0;i<n;i++){
    scanf("%lld%lld",&(P[i].first),&(P[i].second));
    P[i].first+=P[i].second;
  }
  sort(P,P+n);
  static ll dp[5010][5010];
  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=0;i<n;i++){
    for(int j=0;j<=i;j++){
      if(dp[i][j]<=P[i].first-P[i].second){
	dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+P[i].second);
      }
      dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
    }
  }
  int ans=0;
  for(int j=0;j<=n;j++){
    if(dp[n][j]<INF)ans=j;
  }
  printf("%d\n",ans);
  return 0;
}
