import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		int next =1;

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		}
		System.out.println(-1);
	}
	public static int sample() {
		return 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[] array = new int[N];
		int next =1;

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		}
		System.out.println(-1);
	}
	public static int sample() {
		return 1;
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		int next =1;

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

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-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[] array = new int[N]; array new int[N] N int next =1; next 1 for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			array[i]=sc.nextInt();
		} {
			array[i]=sc.nextInt();
		} array[i]=sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		} {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		} if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			} array[next-1] == 2 array[next-1] array next-1 next 1 2 {
				System.out.println(i+1);
				System.exit(0);
			} System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 System.exit(0) System.exit System 0 next = array[next-1] next array[next-1] array next-1 next 1 System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public static int sample() {
		return 1;
	} sample {
		return 1;
	} return 1; 1 public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		int next =1;

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		}
		System.out.println(-1);
	}
	public static int sample() {
		return 1;
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		int next =1;

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		}
		System.out.println(-1);
	}
	public static int sample() {
		return 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[] array = new int[N];
		int next =1;

		for(int i=0;i<N;i++) {
			array[i]=sc.nextInt();
		}
		for(int i=0;i<N;i++) {
			if(array[next-1] == 2) {
				System.out.println(i+1);
				System.exit(0);
			}
			next = array[next-1];
		}
		System.out.println(-1);
	}
	public static int sample() {
		return 1;
	}

}
