#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
struct node
{
int l, r, t;
bool operator < (node a) const
{
if(r == a.r)
return l<a.l;
return r<a.r;
}
}a[150005];
priority_queue <int, vector<int>, less<int> > q;
int main()
{
int n, x;
cin>>n;
for(int i = 0; i<n; i++) {
scanf("%d%d", &a[i].t, &a[i].r);
a[i].l = a[i].r-a[i].t;
}
sort(a, a+n);
int ans = 0, now = 0;
for(int i = 0; i<n; i++) {
if(a[i].l>=now) {
ans++;
now += a[i].t;
q.push(a[i].t);
} else {
int tmp = q.top();
if(tmp>a[i].t) {
now = now-tmp+a[i].t;
q.pop();
q.push(a[i].t);
}
}
}
cout<<ans<<endl;
return 0;
}