// task name is exams

#include <bits/stdc++.h>

#define ONLINE

using namespace std;

const int N = 1e4 + 5;

pair <int, int> a[N];

multiset <int>::iterator prev(multiset <int>::iterator it)
{
    it--;
    return it;
}

int main()
{
    #ifdef ONLINE
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #endif // ONLINE

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

    multiset <int> s;
    int free = 0;
    for (int i = 0; i < n; i++)
    {
        if (i == 0) free = a[i].first;
        else free += a[i].first - a[i - 1].first;

        if (free >= a[i].second)
        {
            free -= a[i].second;
            s.insert(a[i].second);
        }
        else
        {
            if (!s.empty() && *prev(s.end()) > a[i].second)
            {
                free += *(prev(s.end())) - a[i].second;
                s.erase(prev(s.end()));
                s.insert(a[i].second);
            }
        }
    }

    cout << s.size();

    return 0;
}
