#include <bits/stdc++.h>
using namespace std;
const int kInf = numeric_limits<int>::max();

int main() {
    int n; cin >> n;
    vector<int> h(n, 0), p(n, 0);

    for (int i = 0; i < n; i += 1)
        cin >> h[i] >> p[i];

    vector<int> perm(n, 0);

    for (int i = 0; i < n; i += 1) {
        perm[i] = i;
    }

    sort(perm.begin(), perm.end(), [&] (int a, int b) {
        return h[a] + p[a] < h[b] + p[b];
    });
    
    vector<vector<int>> dp(n + 1, vector<int> (n + 1, kInf));
    
    dp[0][0] = 0;

    for (int i = 0; i < n; i += 1) {
        for (int j = 0; j <= i; j += 1) {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (h[perm[i]] >= dp[i][j]) {
                dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + p[perm[i]]);
            }
        }
    }

    for (int i = n; i >= 0; i -= 1) {
        if (dp[n][i] < kInf) {
            cout << i << "\n";
            return 0;
        }
    }
}