"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const A = arg.slice(1, N + 1).map(n=>parseInt(n));
    
    let now = 0;
    let cnt = 0;
    let done = [];
    
    while(true) {
        now = A[now] - 1;
        
        if(now === 1) {
            cnt++;
            console.log(cnt);
            return;
        }
        
        cnt++;
        
        console.log("now:" + now)
        console.log("done:" + done)
        
        if(done.indexOf(now) !== -1) {
            console.log(-1);
            return;
        }
        
        done.push(now);
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));