function Main(input) {
    input = input.split("\n");
    var line = input[0].split(" ");
    var num = parseInt(line[0]);
    var signals = [];
    signals[0] = 0;
    var ans = -1;
    for(var i = 0; i < num;i++){
        signals[i+1] = parseInt(input[i+1]);
    }
    var current = 1;
    var count = 1
    while(1){
        current = signals[current];
        if(current === 2){
            ans = count;
            break;
        }
        count++;
        if(count>10001){
            break;
        }
    }
//    console.dir(signals);
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));