import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		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 count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	}

} 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[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	}

} Main public static void main(String[] args) {
		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 count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	} main {
		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 count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	} Scanner sc = new Scanner(System.in); sc 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 count = 0; count 0 int button = 1; button 1 int[] b = new int[n]; b new int[n] n while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		} true {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		} b[button - 1] = 1 b[button - 1] b button - 1 button 1 1 button = a[button - 1] button a[button - 1] a button - 1 button 1 count++ count if (button == 2) {
				System.out.println(count);
				break;
			} button == 2 button 2 {
				System.out.println(count);
				break;
			} System.out.println(count) System.out.println System.out System System.out count break; if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			} b[button - 1] == 1 b[button - 1] b button - 1 button 1 1 {
				System.out.println(-1);
				break;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 break; sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		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 count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		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 count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	}

} 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[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

		int count = 0;
		int button = 1;
		int[] b = new int[n]; // 押されたボタン判定用
		while (true) {
			b[button - 1] = 1;
			button = a[button - 1];
			count++;

			if (button == 2) {
				System.out.println(count);
				break;
			}

			if (b[button - 1] == 1) {
				System.out.println(-1);
				break;
			}
		}



		sc.close();
	}

}
