const val INF = Long.MAX_VALUE / 4

data class Person(val h: Long, val p: Long)

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val persons = Array(n, {
    val (h, p) = readLine()!!.split(" ").map(String::toLong)
    Person(h, p)
  })
  persons.sortWith(
      java.util.Comparator { p1, p2 -> java.lang.Long.compare(p1.h + p1.p, p2.h + p2.p) })
  val dp = LongArray(n + 1, { if (it == 0) 0 else INF })
  for (person in persons) {
    for (k in n - 1 downTo 0) {
      if (dp[k] <= person.h) {
        dp[k + 1] = Math.min(dp[k + 1], dp[k] + person.p)
      }
    }
  }
  // println(dp.toList())
  println(dp.withIndex().filter { it.value < INF }.map { it.index }.max()!!)
}
