object Main extends App {
  val input = io.Source.stdin.getLines.toIndexedSeq.map(_.toInt)
  
  private def func():Int={
  	var i=0
    var next=1
    while(next != 2){
      next=input(next)
      if(next == 1) return -1
      i += 1
  	}
    i
  }
  println(func())
}
