#include <bits/stdc++.h>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

const i64 INFT = 1LL << 60LL;

int N;
i64 H[5050], P[5050];

i64 dp[5050][5050];

void chmin(i64& a, i64 b) { a = min(a, b); }

int main()
{
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%lld%lld", H + i, P + i);

	vector<pair<i64, pair<i64, i64> > > ppl;
	for (int i = 0; i < N; ++i) ppl.push_back({ H[i] + P[i], {H[i], P[i]} });
	sort(ppl.begin(), ppl.end());

	for (int i = 0; i < N; ++i) {
		H[i] = ppl[i].second.first;
		P[i] = ppl[i].second.second;
	}

	for (int i = 0; i <= N; ++i) {
		for (int j = 0; j <= N; ++j) dp[i][j] = INFT;
	}
	dp[0][0] = 0;

	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= i; ++j) {
			chmin(dp[i + 1][j], dp[i][j]);
			if (dp[i][j] <= H[i]) chmin(dp[i + 1][j + 1], dp[i][j] + P[i]);
		}
	}

	for (int i = N; i >= 0; --i) {
		if (dp[N][i] < (1LL << 40LL)) {
			printf("%d\n", i);
			return 0;
		}
	}
	return 0;
}