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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef pair<int, int> i_i;
const ll INF = LLONG_MAX / 2;
const int MOD = 1e9 + 7;

int main() {
	int N; cin >> N;
	vector<int> a(N), b(N);
	rep(i, N) cin >> a[i] >> b[i];
	vector<i_i> ci(N);
	rep(i, N) ci[i] = i_i(a[i] + b[i], i);
	sort(ci.begin(), ci.end());
	vector<int> _a(N), _b(N);
	rep(i, N) {
		int _i = ci[i].second;
		_a[i] = a[_i], _b[i] = b[_i];
	}
	a = _a, b = _b;
	vector<ll> dp(N + 1, INF);
	dp[0] = 0;
	rep(i, N) {
		int x = a[i], y = b[i];
		vector<ll> _dp = dp;
		rep(z, N + 1) if (dp[z] <= x) _dp[z + 1] = min(_dp[z + 1], dp[z] + y);
		dp = _dp;
	}
	int ans = 0;
	rep(z, N + 1) if (dp[z] < INF) ans = z;
	cout << ans << endl;
}
