'use strict';
function Main(stdin){
  const input = stdin.trim().split(/\r?\n/g).map(str => Number(str));
  const N = input.shift();
  let btn_num = 1;
  let result = -1;
  let count = 0;

  for(let i = 0; i < N; i++){
    btn_num = input[btn_num-1];
    count++;
    if(btn_num === 2){
        result = count;
        break;
    }
  }
  console.log(result);
}

// 固定
Main(require("fs").readFileSync("/dev/stdin", "utf8"));