#include <bits/stdc++.h>

using namespace std;

typedef pair <long ,long> pll;
typedef set<long>::iterator si;
#define t first
#define d second

vector <pll> v;
set <pll> s;
long long n;

int main()
{
    ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
    cin >> n;
    v.resize(n);
    for (long i = 0;i < n;i++)cin >> v[i].t >> v[i].d;
    sort(v.begin(),v.end());
    long long ans = 0,temp = 0;
    long long sumd = 0;
    long Max = 0;
    for (long i = 0;i < n;i++){
        Max = max(Max,v[i].t);
        sumd += v[i].d;
        s.insert(make_pair(-v[i].d,i));
        temp++;
        while(s.size() > 0 && sumd > Max){
            temp--;
            pll tmp = *s.begin();
            s.erase(s.begin());
            if (tmp.d == i){
                    if (i != 0)Max = v[i-1].t;
                    else Max = 0;
            }
            sumd -= v[tmp.d].d;
        }

        if (sumd <= Max) ans = max(ans,temp);

    }
    cout << ans << '\n';
    return 0;
}
// 3 3 2 5 3 10 5
