object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val macho = Array.tabulate(n){_ ⇒
    val Array(c, w) = readLine.trim.split(' ').map(_.toInt)
    Macho(c, w)
  }

  println(countMin(macho))
  def countMin(macho: Array[Macho]): Int = {
    val min = Array.tabulate(macho.length + 1){i ⇒ macho.length - i}
    val canBeOne = calCanBeOne(macho)
    for (right ← min.indices.tail.reverse; left ← 0 until right if canBeOne(left)(right - 1)){
      min(left) = math.min(min(left), min(right) + 1)
    }
    min(0)
  }
  def calCanBeOne(macho: Array[Macho]): Array[Array[Boolean]] = {
    val res = Array.tabulate(macho.length){_ ⇒ Array.tabulate(macho.length){_ ⇒ false}}
    val weights = (0 +: macho.map(_.weight)).also{a ⇒ a.indices.tail.foreach(i ⇒ a(i) += a(i - 1))}

    def subWeight(from: Int, to: Int): Int ={
      weights(to + 1) - weights(from)
    }
    def sub(from: Int, to: Int, cache: Boolean = false): Boolean = {
      if (cache) res(from)(to)
      else {
        if (from == to) res(from)(to) = true
        else res(from)(to) = (res(from)(to - 1) && subWeight(from, to - 1) <= macho(to).power) || (res(from + 1)(to) && subWeight(from + 1, to) <= macho(from).power)
        res(from)(to)
      }
    }
    for (length ← 0 until n; a ← 0 until n - length) {
      sub(a, a + length)
    }
    res
  }

  case class Macho(power: Int, weight: Int)
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
    @inline
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

