import java.io.InputStreamReader;
import java.util.Scanner;
 
public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	}
} import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	}
} Main public static final long sosu = 1000000007; sosu 1000000007 public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	} main {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	} try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		} {
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		} Scanner scan = new Scanner(new InputStreamReader(System.in)) Scanner scan = new Scanner(new InputStreamReader(System.in)) new Scanner(new InputStreamReader(System.in)) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] buttons = new int[N+1]; buttons new int[N+1] N+1 N 1 for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			} int i = 1; int i = 1; i 1 i<=N i N i++ i++ i {
				buttons[i] = scan.nextInt();
			} {
				buttons[i] = scan.nextInt();
			} buttons[i] = scan.nextInt() buttons[i] buttons i scan.nextInt() scan.nextInt scan int ans = 0; ans 0 int on = 1; on 1 while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			} ans < N ans N {
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			} on = buttons[on] on buttons[on] buttons on ans++ ans if(on == 2){
					System.out.println(ans);
					return;
				} on == 2 on 2 {
					System.out.println(ans);
					return;
				} System.out.println(ans) System.out.println System.out System System.out ans return; System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	}
} public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	}
} Main
import java.io.InputStreamReader;
import java.util.Scanner;
 
public class Main {
	public static final long sosu = 1000000007;
	public static void main(String[] args) {
		try(Scanner scan = new Scanner(new InputStreamReader(System.in))){
			int N = scan.nextInt();
			int[] buttons = new int[N+1];
			
			for(int i = 1; i<=N; i++){
				buttons[i] = scan.nextInt();
			}
			
			int ans = 0;
			int on = 1;
			while(ans < N){
				on = buttons[on];
				ans++;
				if(on == 2){
					System.out.println(ans);
					return;
				}
			}
			
			System.out.println(-1);
		}
	}
}
