#include<bits/stdc++.h>
#define P pair<int,int>
using namespace std;
const int N=5e4+7;
int m,s,n,ans;
P a[N];
priority_queue<P> que;
bool cmp(P a,P b) {return (a.first+a.second)<(b.first+b.second);}
int main()
{
freopen("dlh.in","r",stdin);
freopen("dlh.out","w",stdout);
scanf("%d",&n);
for (int i=1;i<=n;i++)
{
int x,y;scanf("%d%d",&x,&y);
a[i]=make_pair(x,y);
}
sort(a+1,a+n+1,cmp);
for (int i=1;i<=n;i++)
{
if (s<=a[i].second) ans++,que.push(a[i]),s+=a[i].first;
else
{
P x=que.top();
if (x.first>=a[i].first)
{
que.pop();s=s-x.first+a[i].first;
que.push(a[i]);
}
}
}
printf("%d\n",ans);
return 0;
}