import java.util.BitSet;
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}

		BitSet touched = new BitSet(N);
		int i = A[0];
		int result = 0;
		while (i != 1){
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		}
		System.out.println(result + 1);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
} import java.util.BitSet; BitSet java.util import java.util.Scanner; Scanner java.util final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}

		BitSet touched = new BitSet(N);
		int i = A[0];
		int result = 0;
		while (i != 1){
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		}
		System.out.println(result + 1);
	}
} Solver static final Solver INSTANCE = new Solver(); INSTANCE new Solver() void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}

		BitSet touched = new BitSet(N);
		int i = A[0];
		int result = 0;
		while (i != 1){
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		}
		System.out.println(result + 1);
	} solve {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}

		BitSet touched = new BitSet(N);
		int i = A[0];
		int result = 0;
		while (i != 1){
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		}
		System.out.println(result + 1);
	} int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = sc.nextInt() - 1;
		} {
			A[i] = sc.nextInt() - 1;
		} A[i] = sc.nextInt() - 1 A[i] A i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 BitSet touched = new BitSet(N); touched new BitSet(N) int i = A[0]; i A[0] A 0 int result = 0; result 0 while (i != 1){
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		} i != 1 i 1 {
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		} if (touched.get(i)) {
				System.out.println(-1);
				return;
			} touched.get(i) touched.get touched i {
				System.out.println(-1);
				return;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 return; touched.set(i) touched.set touched i result++ result i = A[i] i A[i] A i System.out.println(result + 1) System.out.println System.out System System.out result + 1 result 1 Scanner sc sc class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
} Main public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	} main {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) Solver.INSTANCE.solve(in) Solver.INSTANCE.solve Solver.INSTANCE Solver Solver.INSTANCE in in.close() in.close in String... args args
import java.util.BitSet;
import java.util.Scanner;

final class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt() - 1;
		}

		BitSet touched = new BitSet(N);
		int i = A[0];
		int result = 0;
		while (i != 1){
			if (touched.get(i)) {
				System.out.println(-1);
				return;
			}

			touched.set(i);
			result++;
			i = A[i];
		}
		System.out.println(result + 1);
	}
}

class Main {
	public static void main(String... args) {
		Scanner in = new Scanner(System.in);

		Solver.INSTANCE.solve(in);

		in.close();
	}
}