import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto N = readln.chomp.to!long;
    auto a = N.iota.map!(_ => readln.chomp.to!long-1).array;
    long c = 0;
    foreach (i; 0..N) {
        c = a[c];
        if (c == 1) {
            writeln(i+1);
            return;
        }
    }
    writeln(-1);
}

