import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] button = new int[N];
		for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		}

		int p = 0;
		for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		}
		System.out.println(-1);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] button = new int[N];
		for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		}

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

		int p = 0;
		for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		}
		System.out.println(-1);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] button = new int[N];
		for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		}

		int p = 0;
		for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		}
		System.out.println(-1);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] button = new int[N]; button new int[N] N for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			button[i] = sc.nextInt();
		} {
			button[i] = sc.nextInt();
		} button[i] = sc.nextInt() button[i] button i sc.nextInt() sc.nextInt sc int p = 0; p 0 for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		} {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		} int num = button[p]; num button[p] button p if(num == 2) {
				System.out.println(i+1);
				return;
			} num == 2 num 2 {
				System.out.println(i+1);
				return;
			} System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 return; p = num-1 p num-1 num 1 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) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] button = new int[N];
		for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		}

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

		int p = 0;
		for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		}
		System.out.println(-1);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] button = new int[N];
		for(int i=0; i<N; i++) {
			button[i] = sc.nextInt();
		}

		int p = 0;
		for (int i = 0; i < N; i++ ) {
			int num = button[p];
			if(num == 2) {
				System.out.println(i+1);
				return;
			}
			p = num-1;
		}
		System.out.println(-1);
	}
}
