import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static int mindis = 1000000000;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i= 1;i <= n;i++){
			a[i] = sc.nextInt();
		}
		boolean[] used = new boolean[n+1];
		int c =0;
		int p= 1;
		for(int i= 1;i <= n;i++){

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		}
		
		
		
	}

}

 import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static int mindis = 1000000000;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i= 1;i <= n;i++){
			a[i] = sc.nextInt();
		}
		boolean[] used = new boolean[n+1];
		int c =0;
		int p= 1;
		for(int i= 1;i <= n;i++){

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		}
		
		
		
	}

} Main static int N; N static int M; M static 		ArrayList<ArrayList<Integer>> map; map static boolean[] used; used static int f = 0; f 0 static int s = 0; s 0 static int mindis = 1000000000; mindis 1000000000 static ArrayList<Integer> saitan; saitan public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i= 1;i <= n;i++){
			a[i] = sc.nextInt();
		}
		boolean[] used = new boolean[n+1];
		int c =0;
		int p= 1;
		for(int i= 1;i <= n;i++){

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		}
		
		
		
	} main {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i= 1;i <= n;i++){
			a[i] = sc.nextInt();
		}
		boolean[] used = new boolean[n+1];
		int c =0;
		int p= 1;
		for(int i= 1;i <= n;i++){

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		}
		
		
		
	} 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 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 boolean[] used = new boolean[n+1]; used new boolean[n+1] n+1 n 1 int c =0; c 0 int p= 1; p 1 for(int i= 1;i <= n;i++){

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		} int i= 1; int i= 1; i 1 i <= n i n i++ i++ i {

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		} {

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		} if(used[p]){
				System.out.println(-1);
				return;
			} used[p] used p {
				System.out.println(-1);
				return;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 return; if(p == 2){
				System.out.println(c);
				return;
			} p == 2 p 2 {
				System.out.println(c);
				return;
			} System.out.println(c) System.out.println System.out System System.out c return; c++ c used[p] = true used[p] used p true p = a[p] p a[p] a p String[] args args
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static int mindis = 1000000000;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for(int i= 1;i <= n;i++){
			a[i] = sc.nextInt();
		}
		boolean[] used = new boolean[n+1];
		int c =0;
		int p= 1;
		for(int i= 1;i <= n;i++){

			if(used[p]){
				System.out.println(-1);
				return;
			}
			if(p == 2){
				System.out.println(c);
				return;
			}
			c++;

			used[p] = true;
			p = a[p];
			
		}
		
		
		
	}

}


