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

#define ll long long
#define mp make_pair
#define pb push_back

int n;
pair <int, pair <int, int> > v[5005];
ll f[5005][5005];

int main() {
	ios :: sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; ++ i) {
		cin >> v[i].second.first >> v[i].second.second;
		v[i].first = v[i].second.first + v[i].second.second;
	}
	sort(v, v + n);
	memset(f, 0x3f, sizeof(f));
	f[0][0] = 0;
	for (int i = 0; i < n; ++ i) {
		int h = v[i].second.first;
		int p = v[i].second.second;
		for (int j = 0; j <= i; ++ j) {
			//
			if (f[i][j] <= h)
				f[i + 1][j + 1] = min(f[i + 1][j + 1], f[i][j] + p);
			//
			f[i + 1][j] = min(f[i + 1][j], f[i][j]);
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; ++ i)
		if (f[n][i] < 0x3f3f3f3f3f3f3f3f)
			ans = i;
	cout << ans << endl;
	return 0;
}