function main(data){
    input = data.split("\n");
    len = input[0];
    count = 0;
    temp = input.concat();
    index = temp[1];
    input[1] = 0;
    while(true){
        count += 1;
        if(index == 2){
            console.log(count)
            break;
        }
        index = temp[index];
        if(!input[index]){
            console.log(-1);
            break;
        }
        input[index] = 0;
    }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));