import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val ar = Range(0, n).map(_ => sc.nextInt - 1)
    .toArray

  println(solve(ar))

  def solve(ar: Array[Int]): Int = {
    var p = 0
    for (i <- 0 to ar.length) {
      p match {
        case 1 =>
          return i
        case _ if ar(p) < 0 => return -1
        case _ =>
          val n = ar(p)
          ar(p) = -1
          p = n
      }
    }
    return -1
  }
}
