#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<queue>
#define FOR(i,a,b) for(i=(a);i<=(b);i++)
#define ROF(i,a,b) for(i=(a);i>=(b);i--)
#define mmt(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define mp make_pair
#define N 300010
using namespace std;
typedef long long LL;
typedef long double LD;
struct poi{int t1,t2;}a[N];
bool cmp(poi a,poi b){return a.t2<b.t2;}
priority_queue<int> heap;
int n;
int main()
{
  ios::sync_with_stdio(false);
  scanf("%d",&n);int i;
  FOR(i,1,n) scanf("%d%d",&a[i].t1,&a[i].t2);
  sort(a+1,a+1+n,cmp);
  int used=0,cnt=0;
  FOR(i,1,n)
  {
    cnt++;heap.push(a[i].t1);
    used+=a[i].t1;
    if (used>a[i].t2) 
    {
      used-=heap.top();
      heap.pop();cnt--;
    }
  }
  printf("%d\n",cnt);
  return 0;
}