import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = scan.nextInt();
		} {
			a[i] = scan.nextInt();
		} a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan int now = 0; now 0 int count = 1; count 1 for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		} int i = 0; int i = 0; i 0 i < 1000001 i 1000001 i++ i++ i {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		} {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		} if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			} a[now] == 2 a[now] a now 2 {
				System.out.println(count);
				return;
			} System.out.println(count) System.out.println System.out System System.out count return; {
				now = a[now]-1;
				count++;
			} now = a[now]-1 now a[now]-1 a[now] a now 1 count++ count 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 scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int now = 0;
		int count = 1;
		for (int i = 0; i < 1000001; i++) {
			if (a[now] == 2) {
				System.out.println(count);
				return;
			} else {
				now = a[now]-1;
				count++;
			}
		}
		System.out.println(-1);
	}
}
