import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val a = Array.fill(n)(readInt() -1)

  def solve(): Int = {
    var cnt = 1
    var pushedButtons = Set.empty[Int]
    var btn = a.head
    while(!pushedButtons(btn)) {
      if(btn == 1) return cnt
      else {
        pushedButtons = pushedButtons + btn
        btn = a(btn)
        cnt += 1
      }
    }
    -1
  }

  println(solve())

}

