'use strict'
const inArray = (needle, haystack) => haystack.some(item => item === needle)

const main = (input) => {
    input = input.split('\n').map(v => parseInt(v))
    const N = input[0]
    const a = input.slice(1, N + 1).map(v => v - 1)

    let i = 0
    let arr = []
    while(true){
        let next = a[i]
        if(!inArray(i, arr)){
            arr.push(i)
        }else{
            break
        }
        i = next
    }
    if(inArray(1, arr)){
        console.log(arr.length - 1)
    }else{
        console.log(-1)
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))