import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), a[][] = new int[N][2], ans = 0, tmp = 0;
		for (int i = 0; i < N; ++i) a[i][0] = sc.nextInt();
		sc.close();
		for (int i = 0; a[i][0] != 2; ++ans) {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		}
		if (tmp == 0) System.out.print(ans + 1);
		else System.out.print(-1);
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), a[][] = new int[N][2], ans = 0, tmp = 0;
		for (int i = 0; i < N; ++i) a[i][0] = sc.nextInt();
		sc.close();
		for (int i = 0; a[i][0] != 2; ++ans) {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		}
		if (tmp == 0) System.out.print(ans + 1);
		else System.out.print(-1);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), a[][] = new int[N][2], ans = 0, tmp = 0;
		for (int i = 0; i < N; ++i) a[i][0] = sc.nextInt();
		sc.close();
		for (int i = 0; a[i][0] != 2; ++ans) {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		}
		if (tmp == 0) System.out.print(ans + 1);
		else System.out.print(-1);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), a[][] = new int[N][2], ans = 0, tmp = 0;
		for (int i = 0; i < N; ++i) a[i][0] = sc.nextInt();
		sc.close();
		for (int i = 0; a[i][0] != 2; ++ans) {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		}
		if (tmp == 0) System.out.print(ans + 1);
		else System.out.print(-1);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt() N sc.nextInt() sc.nextInt sc a[][] = new int[N][2] a new int[N][2] N 2 ans = 0 ans 0 tmp = 0; tmp 0 for (int i = 0; i < N; ++i) a[i][0] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N ++i ++i i a[i][0] = sc.nextInt(); a[i][0] = sc.nextInt() a[i][0] a[i] a i 0 sc.nextInt() sc.nextInt sc sc.close() sc.close sc for (int i = 0; a[i][0] != 2; ++ans) {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		} int i = 0; int i = 0; i 0 a[i][0] != 2 a[i][0] a[i] a i 0 2 ++ans ++ans ans {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		} {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		} if (a[i][1] == 1) {
				tmp = 1;
				break;
			} a[i][1] == 1 a[i][1] a[i] a i 1 1 {
				tmp = 1;
				break;
			} tmp = 1 tmp 1 break; a[i][1] = 1 a[i][1] a[i] a i 1 1 i = a[i][0] - 1 i a[i][0] - 1 a[i][0] a[i] a i 0 1 if (tmp == 0) System.out.print(ans + 1);
		else System.out.print(-1); tmp == 0 tmp 0 System.out.print(ans + 1) System.out.print System.out System System.out ans + 1 ans 1 System.out.print(-1) System.out.print System.out System System.out -1 1 String[] args args
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), a[][] = new int[N][2], ans = 0, tmp = 0;
		for (int i = 0; i < N; ++i) a[i][0] = sc.nextInt();
		sc.close();
		for (int i = 0; a[i][0] != 2; ++ans) {
			if (a[i][1] == 1) {
				tmp = 1;
				break;
			}
			a[i][1] = 1;
			i = a[i][0] - 1;
		}
		if (tmp == 0) System.out.print(ans + 1);
		else System.out.print(-1);
	}
}