import scala.collection.immutable.Nil
import scala.collection.mutable

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

  val n = readInt
  val events = Array.tabulate(n - 1){_ ⇒
    val Array(l, r) = readLine.trim.split(' ').map(_.toInt)
    Event(l, r)
  }
  val branch = Branch(events)
  println(branch.canSaveTime)
  case class Event(left: Int, right: Int)
  object Branch {
    def apply(events: Array[Event]): Branch = {
      val refCount = Array.tabulate(events.length + 1){_ ⇒ 0}
      val reference = Array.tabulate(events.length + 1){_ ⇒ Nil: List[Int]}
      for (i ← events.indices){
        val Event(left, right) = events(i)
        refCount(i) += 2
        reference(left - 1) ::= i
        reference(right - 1) ::= i
      }
      val depth = calDepth(events)
      val branches = Array.tabulate(events.length + 1){_ ⇒ Ending: Branch}
      val queue = mutable.Queue[Int](events.length)
      while (queue.nonEmpty){
        val top = queue.dequeue()
        for (prev ← reference(top)) {
          refCount(prev) -= 1
          if (refCount(prev) == 0){
            queue.enqueue(prev)
            val Event(left, right) = events(prev)
            branches(prev) = Choice(depth(prev), branches(left - 1), branches(right - 1))
          }
        }
      }
      branches(0)
    }
    private[this] def calDepth(events: Array[Event]): Array[Int] = {
      val depth = Array.tabulate(events.length + 1){_ ⇒ -1}.also{d ⇒ d(0) = 0
        d(events.length) = 0}
      val queue = mutable.Queue[Int](0)
      while (queue.nonEmpty){
        val top = queue.dequeue()
        val Event(left, right) = events(top)
        if (depth(left - 1) == -1) {
          depth(left - 1) = depth(top) + 1
          queue.enqueue(left - 1)
        }
        if (depth(right - 1) == -1){
          depth(right - 1) = depth(top) + 1
          queue.enqueue(right - 1)
        }
      }
      depth
    }

  }
  sealed trait Branch {
    def endingCount: Int
    def canSaveTime: Long
    def cannotSaveTime: Long
  }
  case object Ending extends Branch {
    override def endingCount: Int = 1
    override def canSaveTime: Long = 0
    override def cannotSaveTime: Long = 0
  }
  case class Choice(depth: Int, left: Branch, right: Branch) extends Branch {
    override val endingCount = left.endingCount + right.endingCount
    override val canSaveTime: Long = List(
      left.cannotSaveTime + right.cannotSaveTime + endingCount,
      left.cannotSaveTime + right.canSaveTime + left.endingCount + 1,
      left.canSaveTime + right.cannotSaveTime + right.endingCount + 1,
      left.canSaveTime + right.canSaveTime + depth + 2
    ).min
    override val cannotSaveTime: Long = left.cannotSaveTime + right.cannotSaveTime + endingCount
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def also(@inline func: T ⇒ Unit): T = {
      func(value)
      value
    }
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
  }
}
