import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	}
} import java.io.InputStream; InputStream java.io import java.util.Scanner; Scanner java.util public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	}
} Main static Scanner sc; sc public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	} main {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	} InputStream in = System.in; in System.in System System.in sc = new Scanner(in) sc new Scanner(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] = sc.nextInt() - 1 a[i] a i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int answer = 0; answer 0 int nowPoint = 0; nowPoint 0 while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		} nowPoint + 1 != 2 nowPoint + 1 nowPoint 1 2 {
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		} int prePoint = nowPoint; prePoint nowPoint nowPoint = a[nowPoint] nowPoint a[nowPoint] a nowPoint a[prePoint] = -1 a[prePoint] a prePoint -1 1 answer++ answer if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			} nowPoint == -1 nowPoint -1 1 {
				answer = -1;
				break;
				//System.out.println("out");
			} answer = -1 answer -1 1 break; System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	}
} public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	}
} Main
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	}
}