//Link : https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_c

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 5005
#define inf 1000000000000000000LL

pair<int,int> in[N];
int H[N],P[N];

ll dp[N][N];
void solve() {
  int n;scanf("%d ", &n);
  for(int i=0;i<n;++i) {
    scanf("%d %d ", &H[i],&P[i]);
    in[i] = make_pair(H[i]+P[i],i);
  }
  sort(in,in+n);
  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) {
    int h = H[in[i].second],p = P[in[i].second];
    for(int j=i;j>=0;--j) {
      if(dp[i][j]==inf) {
        continue;
      }
      if(dp[i][j]<=h) {
        dp[i+1][j+1] = min(dp[i+1][j+1], dp[i][j] + p);
      }
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
  }
  for(int i=n;i>=0;--i) {
    if(dp[n][i]!=inf) {
      printf("%d\n", i);
      return;
    }
  }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}
