object Main extends App {
	val n = scala.io.StdIn.readInt
	val a = new Array[Int](n)

	for(i<-0 until n){
		a(i) = scala.io.StdIn.readInt - 1
	}

	var ans = 1
	var tp = 0

	while(ans < n && a(tp) != 1){
		tp = a(tp)
		ans += 1
	}

	if(ans == n) println(-1)
	else println(ans)

} 