object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN) = readLine.split(" ").map(_.toInt)
    val datA = for(i <- 1 to datN) yield (readLine.split(" ").map(_.toInt).head)

    val sb = datA.map{x => (false, x - 1)}.toVector
    def traverse(result: Int, pos: Int, sb: Vector[(Boolean, Int)]): Int = sb(pos) match {
      case (arrived, _) if (arrived) => -1
      case (_, next) if(next == 1) => result
      case (_, next) => traverse(result + 1, next, sb.updated(pos, (true, next)))
    }
    val ans = traverse(1, 0, sb)

    println(ans)
  }
}
