fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val an = IntArray(n, { readLine()!!.toInt() })
  val selected = BooleanArray(n, { false })
  
  var s = 0;
  var count = 0;
  while(true){
    if (selected[s]){
      count = -1;
      break;
    }
    selected[s] = true;
  	s = an[s] - 1;
    count += 1;
    if (s == 1){
      break;
    }
  } 
  println(count);
}