#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define die(x) { cout << x; return 0; }
#define int lint

using namespace std;
typedef long long lint;
typedef long long ll;
typedef pair<int, int> pii;
const int inf = 1000*1000*1000 + 7, Nmax = 1e4+1;

pii arr[Nmax];
signed main() {
    cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

    int n;
    cin >> n;
    for(int i = 0;i < n;++i)
        cin >> arr[i].first >> arr[i].second;

    sort(arr, arr+n);
    ll sum = 0;
    priority_queue<int> q;
    for(int i = 0;i < n;++i) {
        sum += arr[i].second;
        q.push(arr[i].second);
        if(sum > arr[i].first) {
            sum -= q.top();
            q.pop();
        }
    }
    cout << q.size() << '\n';
    return 0;
}
