import java.util.Scanner

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val n:Int = sc.nextInt()
    val button = IntArray(n+1)
    val map = IntArray(n+1)
    for(i in 1..n){
      button[i] = sc.nextInt()
      map[i] = 0
    }

    var i = 1
    var count = 0
    do{
      map[i] = 1
      count++
      i = button[i]
    }while(map[i]!=1&&i!=2)

    if(i==2) println(count)
    else println(-1)
}
