func main() {
    let N = Int(readLine()!)!
    let A = (0..<N).map { _ in
        Int(readLine()!)! - 1
    }

    var on = Array(repeating: false, count: N)
    var x = 0
    var count = 0
    while x != 1 {
        let c = A[x]
        guard !on[c] else {
            print(-1)
            return
        }
        on[c] = true
        x = c
        count += 1
    }

    print(count)

}

main()