import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)
    val N = in.nextInt()

    val ph = (0 until N).map { _ =>
      val h = in.nextLong()
      val p = in.nextLong()
      (p, h)
    }.sorted

    val inf = Long.MaxValue >> 10

    val dp = Array.fill[Long](N + 1)(inf)
    dp(0) = 0
    for {
      (p, h) <- ph
      i <- (N - 1) to 0 by -1
      if dp(i) <= h
    } {
      dp(i + 1) = math.min(dp(i) + p, dp(i + 1))
    }

    var ans = 0
    for (i <- 0 to N) {
      if (dp(i) < inf) {
        ans = i
      }
    }
    println(ans)
  }
}
