import java.util.*;

public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		}
	}
} import java.util.*; util.* java public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		}
	}
} Main public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		}
	} main {
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		}
	} try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		} {
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) 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();
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				A[i] = sc.nextInt();
			} {
				A[i] = sc.nextInt();
			} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int now = 0; now 0 for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			} {
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			} now = A[now] - 1 now A[now] - 1 A[now] A now 1 if(now == 1) {
					System.out.println(i+1);
					return;
				} now == 1 now 1 {
					System.out.println(i+1);
					return;
				} System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 return; System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		}
	}
} public class Main{
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)){
			int N = sc.nextInt();
			int[] A = new int[N];
			for(int i = 0; i < N; i++){
				A[i] = sc.nextInt();
			}
			int now = 0;
			for(int i = 0; i < N; i++){
				now = A[now] - 1;
				if(now == 1) {
					System.out.println(i+1);
					return;
				}
			}
			System.out.println(-1);
		}
	}
} Main
import java.util.*;

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