import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readInt
import scala.util.control.Breaks.break

object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val list: ListBuffer[Int] = scala.collection.mutable.ListBuffer.empty[Int]
    list += 0

    for(i <- 1.to(n)) {
      list += readInt()
    }

    var pos = 1
    var cnt = 0

    while (pos != 2) {
      if(list(pos) == -1) {
        println(-1)
        return
      }
      val next = list(pos)
      list(pos) = -1
      pos = next
      cnt.+=(1)
    }

    print(cnt)
  }
}

