#include "bits/stdc++.h"
using namespace std;

bool check(vector<pair<long long int, long long int>>&ps) {
	long long int  now = 0;
	for (auto p : ps) {
		if (now <= p.first) {
			now += p.second;
		}
		else {
			return false;
		}
	}
	return true;
}
int main() { 
	int N; cin >> N;
	vector<pair<long long int,long long int>>ps;
	for (int i = 0; i < N; ++i) {
		int h, p; cin >> h >> p;
		ps.emplace_back(h, p);
	}
	sort(ps.begin(), ps.end(), [](const pair<long long int, long long int>l, const pair<long long int, long long int>r) {
		return l.second < r.second;
	});
	long long int now = 0;
	int ans = 0;
	vector<pair<long long int, long long int>>used;
	for (auto p : ps) {
	
		auto nextused = used;
		auto it = lower_bound(nextused.begin(), nextused.end(), p, [](const pair<long long int, long long int>l, const pair<long long int, long long int>r) {
			return l.first + l.second < r.first + r.second;
		});
		nextused.insert(it,p);
		if (check(nextused)) {
			used = nextused;
		}
	}
	ans = used.size();
	cout << ans << endl;
	return 0;
}