#include<cstdio>
#include<cctype>
#include<queue>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define ren for(int i=first[x];i;i=next[i])
using namespace std;
const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c==‘-‘) f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-‘0‘;
return x*f;
}
const int maxn=150010;
struct Building {
int need,t;
bool operator < (const Building& ths) const {return t<ths.t;}
}A[maxn];
priority_queue<int> Q;
int main() {
int n=read(),t=0;
rep(i,1,n) A[i].need=read(),A[i].t=read();
sort(A+1,A+n+1);
rep(i,1,n) {
Q.push(A[i].need);t+=A[i].need;
while(t>A[i].t) t-=Q.top(),Q.pop();
}
printf("%d\n",Q.size());
return 0;
}