#include<bits/stdc++.h>
#define mx 5005
#define inf 100000000000005
using namespace std;

int n;
long long h, p, dp[mx];
pair<long long, long long> hp[mx];

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