import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	}

} import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	} main {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] as = new int[n]; as new int[n] n for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		} int i=0; int i=0; i 0 i<as.length i as.length as as.length i++ i++ i {
			as[i] = sc.nextInt()-1;
		} {
			as[i] = sc.nextInt()-1;
		} as[i] = sc.nextInt()-1 as[i] as i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 sc.close() sc.close sc int count = 0; count 0 int light = 0; light 0 for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		} int i=0; int i=0; i 0 i<as.length i as.length as as.length i++ i++ i {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		} {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		} count += 1 count 1 light = as[light] light as[light] as light if(light == 1) {
				break;
			} light == 1 light 1 {
				break;
			} break; if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		} count == as.length count as.length as as.length {
			System.out.println(-1);
		} System.out.println(-1) System.out.println System.out System System.out -1 1 {
			System.out.println(count);
		} System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	}

} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] as = new int[n];
		
		for(int i=0; i<as.length; i++) {
			as[i] = sc.nextInt()-1;
		}
		sc.close();
		
		int count = 0;
		int light = 0;
		
		for(int i=0; i<as.length; i++) {
			count += 1;
			light = as[light];
			
			if(light == 1) {
				break;
			}
		}
		
		if(count == as.length) {
			System.out.println(-1);
		}else {
			System.out.println(count);
		}

	}

}
