import io.StdIn.readInt
import annotation.tailrec

object Main extends App {
  val n = readInt
  val as = Seq.fill(n)(readInt)
  val vs = Seq.fill(n)(false)

  println(solve(0, 0, as, vs))

  @tailrec def solve(pos: Int, res: Int, as: Seq[Int], vs: Seq[Boolean]): Int = {
    if (pos == 1) res
    else if (vs(pos)) -1
    else {
      solve(as(pos) - 1, res + 1, as, vs.updated(pos, true))
    }
  }
}
