object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = Array.fill(n)(sc.nextInt()-1)
  val visited = Array.fill(n)(false)

  var now = 0
  var count = 0
  while (now != 1 && !visited(now)) {
    visited(now) = true
    now = a(now)
    count += 1
  }

  println(if (now == 1) count else -1)
}
