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

/// 数列の読み込み
auto readNums(T = int)() {
	return readln().chomp.split.map!(to!T).array;
}

/// 数の読み込み
auto readNum(T = int)() {
	return readNums!T.front;
}

/// 指定行数読み込み
auto readRows(size_t rows) {
	return generate(() => readln().chomp).take(rows).array;
}

struct Switch {
    size_t next;
    bool touch = false;
}

void main() {
    auto switches = readNum.readRows.map!(n => Switch(to!size_t(n))).array;
    for(size_t i = 0, count = 0; !switches[i].touch;) {
        Switch* s = &switches[i];
        s.touch = true;
        i = s.next - 1;
        ++count;
        
        if(i == 1) {
	writefln("%d", count);
        	return;
        }
    }
    
    writefln("-1");
}