#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;
using pll = pair<ll, ll>;

bool cmp(pll &a, pll &b){
	return a.first + a.second < b.first + b.second;
}

ll dp[5500][5500];

int main(){
  int n;
  cin >> n;
  vector<pll> part;
  for(int i = 0; i < n; ++i){
  	ll h, p;
  	cin >> h >> p;
  	part.push_back({h, p});
  }

  sort(part.begin(), part.end(), cmp);

  fill((ll*)dp, (ll*)dp + sizeof(dp) / sizeof(ll), LINF);
  dp[0][0] = 0;
  for(int i = 0; i < n; ++i){
  	for(int j = 0; j <= i + 1; ++j){
  		if(j >= 1 && part[i].first >= dp[i][j - 1])dp[i + 1][j] = min(dp[i][j], dp[i][j - 1] + part[i].second);
  		else dp[i + 1][j] = dp[i][j];
  	}
  }
  cout << lower_bound(dp[n], dp[n] + n + 1, LINF) - dp[n] - 1 << endl;
  return 0;
}
