import java.util.Scanner;

/**
 * https://abc065.contest.atcoder.jp/tasks/abc065_b
 */
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()-1;
		sc.close();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	}

} 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()-1;
		sc.close();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	}

} 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()-1;
		sc.close();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	} 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();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	} 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] a i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 sc.close() sc.close sc boolean[] dp = new boolean[N]; dp new boolean[N] N int i=0; i 0 int ans = 0; ans 0 boolean f = false; f false while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		} !dp[i] dp[i] dp i {
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		} dp[i] = true dp[i] dp i true if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			} i==1 i 1 {
				f = true;
				break;
			} f = true f true break; {
				ans++;
				i = a[i];
			} ans++ ans i = a[i] i a[i] a i System.out.println(f ? ans : -1) System.out.println System.out System System.out f ? ans : -1 f ans -1 1 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()-1;
		sc.close();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	}

} 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()-1;
		sc.close();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	}

} Main
import java.util.Scanner;

/**
 * https://abc065.contest.atcoder.jp/tasks/abc065_b
 */
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()-1;
		sc.close();
		
		boolean[] dp = new boolean[N];
		int i=0;
		int ans = 0;
		boolean f = false;
		while(!dp[i]){
			dp[i] = true;
			if(i==1){
				f = true;
				break;
			}else{
				ans++;
				i = a[i];
			}
		}
		
		System.out.println(f ? ans : -1);
	}

}
