"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  const inf = 2e9;
  var n = next();
  var hh = nextm(n,2);
  hh.sort((a,b)=>a[0]+a[1]-b[0]-b[1]);
  var dp = xArray(inf,n+1);
  dp[0] = 0;
  for(var i = 0; i < n; i++){
    var h = hh[i][0], p = hh[i][1];
    for(var j = i+1; j > 0; j--){
      if(dp[j-1] > h)continue;
      if(dp[j-1]+p < dp[j])dp[j] = dp[j-1]+p;
    }
  }
  for(var i = n; i >= 0; i--)if(dp[i] < inf)return i;
}