import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	}
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main {
	public static void main(String[] args) throws Exception {
		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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	}
} Main public static void main(String[] args) throws Exception {
		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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	} 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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	} 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() - 1;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt() - 1;
		} {
			a[i] = sc.nextInt() - 1;
		} a[i] = sc.nextInt() - 1 a[i] a i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 sc.close() sc.close sc Set<Integer> set = new HashSet<>(); set new HashSet<>() set.add(0) set.add set 0 int i = 0; i 0 int ans = 0; ans 0 while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		} true {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		} int j = a[i]; j a[i] a i ans++ ans if (j == 1) {
				System.out.println(ans);
				return;
			} j == 1 j 1 {
				System.out.println(ans);
				return;
			} System.out.println(ans) System.out.println System.out System System.out ans return; if (!set.add(j)) {
				System.out.println(-1);
				return;
			} !set.add(j) set.add(j) set.add set j {
				System.out.println(-1);
				return;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 return; i = j i j String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	}
} Main
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		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() - 1;
		}
		sc.close();

		Set<Integer> set = new HashSet<>();
		set.add(0);
		int i = 0;
		int ans = 0;
		while (true) {
			int j = a[i];
			ans++;
			if (j == 1) {
				System.out.println(ans);
				return;
			}
			if (!set.add(j)) {
				System.out.println(-1);
				return;
			}
			i = j;
		}
	}
}
