#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const int N = 1e6+5;

struct cell
{
    ll t, d;
};

ll n, dp[N], ma[N], del[N];
cell a[N];

bool cmp(cell a, cell b)
{
    if (a.t != b.t)
        return a.t < b.t;
    return a.d < b.d;
}
multiset<pair<int, int> > s;
signed main()
{
    cin >> n;

    for (int i = 1; i <= n; i++)
        cin >> a[i].t >> a[i].d;
    sort(a+1, a+n+1, cmp);
    int pos = 0, time = 0, x = 0;
    for (int i = 1; i <= n; i++)
    {
        if (a[i].t >= time+a[i].d)
            x++, time += a[i].d, s.insert(make_pair(a[i].d, i));
        else
        {
            if (s.size() > 0)
            {
                int pos = s.rbegin()->second, val = s.rbegin()->first;
                if (val <= a[i].d)
                    continue;
                set<pair<int, int> >::iterator it = s.end();
                it--;
                s.erase(it);
                time -= val-a[i].d;
                s.insert(make_pair(a[i].d, i));
            }
        }
    }
    cout << s.size();
    return 0;
}
