// https://cf17-final.contest.atcoder.jp/tasks/cf17_final_d
#include<iostream>
#include<vector>
#include<algorithm>


int main(){
	std::ios::sync_with_stdio(false);std::cin.tie(nullptr);
	int nPlayer;std::cin>>nPlayer;
	struct player{int height,power;};
	std::vector<player> players(nPlayer);
	for(player& p:players)std::cin>>p.height>>p.power;

	std::sort(players.begin(),players.end(),[](player a,player b){
		return a.height+a.power<b.height+b.power;
	});
	std::vector<long long> minHeight(nPlayer+1,1e18);
	minHeight[0]=0;
	for(player p:players){
		auto it=std::upper_bound(minHeight.begin(),minHeight.end(),p.height);
		while(it!=minHeight.begin()){
			*it=std::min(*it,p.power+*std::prev(it));
			--it;
		}
	}
	std::cout<<std::lower_bound(minHeight.begin(),minHeight.end(),1e18)-minHeight.begin()-1<<'\n';
}