fun main(args: Array<String>) {
  val sc = if (args.size > 1) java.util.Scanner(java.io.File(args[1])) else java.util.Scanner(System.`in`)
  solve(sc)
}

fun solve(sc: java.util.Scanner) {
  val N = sc.nextInt()
  val a = Array(N) { sc.nextInt() }
  var i = 0
  var pos = 0
  while (i < N) {
    pos = a[pos] - 1
    i++
    if (pos == 1) {
      println(i)
      return
    }
  }
  println(-1)
}
