import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int[n];
		int ramp = 1;
		int sum = 0;
		for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		}
		
		while(true){
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		}
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int[n];
		int ramp = 1;
		int sum = 0;
		for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		}
		
		while(true){
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		}
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int[n];
		int ramp = 1;
		int sum = 0;
		for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		}
		
		while(true){
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int[n];
		int ramp = 1;
		int sum = 0;
		for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		}
		
		while(true){
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] data = new int[n]; data new int[n] n int ramp = 1; ramp 1 int sum = 0; sum 0 for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			data[i] = sc.nextInt();
		} {
			data[i] = sc.nextInt();
		} data[i] = sc.nextInt() data[i] data i sc.nextInt() sc.nextInt sc while(true){
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		} true {
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		} if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			} sum>n sum n {
				System.out.println(-1);
				break;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 break; if(ramp == 2){
				System.out.println(sum);
				break;
			} ramp == 2 ramp 2 {
				System.out.println(sum);
				break;
			} System.out.println(sum) System.out.println System.out System System.out sum break; ramp = data[ramp-1] ramp data[ramp-1] data ramp-1 ramp 1 sum++ sum String[] args args
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] data = new int[n];
		int ramp = 1;
		int sum = 0;
		for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		}
		
		while(true){
			if(sum>n){
				System.out.println(-1);
				break;
			}else if(ramp == 2){
				System.out.println(sum);
				break;
			}
			ramp = data[ramp-1];
			sum++;
		}
	}
}