import java.util.*;

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

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	} main {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc List<Integer> A = new ArrayList<Integer>(); A new ArrayList<Integer>() for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			A.add(Integer.parseInt(sc.next()));
		} {
			A.add(Integer.parseInt(sc.next()));
		} A.add(Integer.parseInt(sc.next())) A.add A Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int j = 0; j 0 int ans = 0; ans 0 for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		} {
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		} j = A.get(j)-1 j A.get(j)-1 A.get(j) A.get A j 1 ans += 1 ans 1 if (j == 1){
				System.out.println(ans);
				return;
			} j == 1 j 1 {
				System.out.println(ans);
				return;
			} System.out.println(ans) System.out.println System.out System System.out ans return; System.out.println(-1) System.out.println System.out System System.out -1 1 return; String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	}
} Main
import java.util.*;

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

		int N = Integer.parseInt(sc.next());

		List<Integer> A = new ArrayList<Integer>();

		for (int i=0; i<N; i++){
			A.add(Integer.parseInt(sc.next()));
		}

		int j = 0;
		int ans = 0;
		for (int i=0; i<N; i++){
			j = A.get(j)-1;
			ans += 1;
			if (j == 1){
				System.out.println(ans);
				return;
			}
		}
		System.out.println(-1);
		return;
	}
}