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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	}

} 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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	}

} 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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	} 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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	} 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 k = 0; k 0 int i = 0; i 0 while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		} k <= n && i != 1 k <= n k n i != 1 i 1 {
			i = a[i]-1;
			k++;
		} i = a[i]-1 i a[i]-1 a[i] a i 1 k++ k if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		} k > n k n {
			System.out.println(-1);
		} System.out.println(-1) System.out.println System.out System System.out -1 1 {
			System.out.println(k);
		} System.out.println(k) System.out.println System.out System System.out k 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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	}

} 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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	}

} 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 k = 0;
		int i = 0;
		while(k <= n && i != 1) {
			i = a[i]-1;
			k++;
		}
		if(k > n) {
			System.out.println(-1);
		} else {
			System.out.println(k);
		}
		
	}

}
