#include <bits/stdc++.h>

typedef long long ll;
const ll MOD = 1000000007;

using namespace std;

bool comp(const pair<int, int> &a, const pair<int, int> &b) {
    return ((ll)a.first + a.second) < ((ll)b.first + b.second);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int, int> > v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end(), comp);
    vector<vector<ll> > dp(n + 1, vector<ll>(n + 1, LLONG_MAX));
    int ans = 0;
    dp[0][0] = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (v[i].first >= dp[i][j]) {
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (ll)v[i].second);
                ans = max(ans, j + 1);
            }
        }
    }
    cout << ans;
    return 0;
}