#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
using namespace std;
int n,now,ans;
struct node{int t1,t2;}a[150001];
bool operator<(node a,node b)
{
return a.t2<b.t2;
}
priority_queue<int,vector<int>,less<int> >q;
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d%d",&a[i].t1,&a[i].t2);
sort(a+1,a+n+1);
for (int i=1;i<=n;i++)
if (now+a[i].t1<=a[i].t2)
{
ans++;
now+=a[i].t1;
q.push(a[i].t1);
}
else
{
int x=q.top();
if (a[i].t1<x)
{
q.pop();
q.push(a[i].t1);
now=now-x+a[i].t1;
}
}
printf("%d",ans);
return 0;
}