
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	}
} Main public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	} main {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	} try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		} {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		} 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[] arr = new int[n + 1]; arr new int[n + 1] n + 1 n 1 for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				arr[i + 1] = sc.nextInt();
			} {
				arr[i + 1] = sc.nextInt();
			} arr[i + 1] = sc.nextInt() arr[i + 1] arr i + 1 i 1 sc.nextInt() sc.nextInt sc int count = 0; count 0 int light = 1; light 1 int tmp; tmp do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2); light != 2 light 2 {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} count++ count tmp = arr[light] tmp arr[light] arr light if (tmp == 0) {
					System.out.println("-1");
					return;
				} tmp == 0 tmp 0 {
					System.out.println("-1");
					return;
				} System.out.println("-1") System.out.println System.out System System.out "-1" return; arr[light] = 0 arr[light] arr light 0 light = tmp light tmp System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	}
} public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] arr = new int[n + 1];
			for (int i = 0; i < n; i++) {
				arr[i + 1] = sc.nextInt();
			}

			int count = 0;
			int light = 1;
			int tmp;
			do {
				count++;
				tmp = arr[light];
				if (tmp == 0) {
					System.out.println("-1");
					return;
				}
				arr[light] = 0;
				light = tmp;
			} while (light != 2);
			System.out.println(count);
		}
	}
}
