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+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	}
} 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+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int[] a = new int[N+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	} main {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int[] a = new int[N+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	} 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+1]; a new int[N+1] N+1 N 1 int ans = 0; ans 0 for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		} int i= 1; int i= 1; i 1 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 x = 1; x 1 while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		} ans < N ans N {
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		} x = a[x] x a[x] a x ans++ ans if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			} x == 2 x 2 {
				System.out.println(ans);
				sc.close();
				return;
			} System.out.println(ans) System.out.println System.out System System.out ans sc.close() sc.close sc return; System.out.println("-1") System.out.println System.out System System.out "-1" sc.close() sc.close sc 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+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int N = sc.nextInt();
		int[] a = new int[N+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	}
} 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+1];
		int ans = 0;
		
		for (int i= 1; i <= N; i++){
			a[i] = sc.nextInt();
		}
		int x = 1;
		while (ans < N){
			x = a[x];
			ans++;
			if (x == 2) {
				System.out.println(ans);
				sc.close();
				return;
			}
		}
		
		System.out.println("-1");
		sc.close();
	}
}
