import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val n = readLine.trim.toInt
  val time = Array.tabulate(n){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toInt)
    (a, b)
  }.sortBy(_._2).toList

  println(
    searchMax(time)
  )
  def searchMax(times: List[(Int, Int)], current: Int = 0, queue: mutable.PriorityQueue[Int] = mutable.PriorityQueue()): Int = {
    times match {
      case Nil ⇒ 0
      case (diff, limit)::t if current + diff <= limit ⇒
        queue.enqueue(diff)
        searchMax(t, current + diff, queue) + 1
      case (diff, limit)::t if queue.nonEmpty && queue.head > diff ⇒
        val remove = queue.dequeue()
        queue.enqueue(diff)
        searchMax(t, current - remove + diff, queue)
      case _::t ⇒ searchMax(t, current, queue)
    }
  }

  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}
