import java.util.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	}
} import java.util.*; util.* java import java.util.Arrays; Arrays java.util public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	} 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]; a new int[n] n int[] b = new int[n]; b new int[n] n for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		} int i=0; int i=0; i 0 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 b[0] = 1 b[0] b 0 1 int now = 1; now 1 do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true); true {
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		} if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			} b[a[now-1]-1]==0 b[a[now-1]-1] b a[now-1]-1 a[now-1] a now-1 now 1 1 0 {
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			} b[a[now-1]-1]=b[now-1]+1 b[a[now-1]-1] b a[now-1]-1 a[now-1] a now-1 now 1 1 b[now-1]+1 b[now-1] b now-1 now 1 1 now = a[now-1] now a[now-1] a now-1 now 1 {
				System.out.println(-1);
				break;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 break; if(now==2){
				System.out.println(b[1]-1);
				break;
			} now==2 now 2 {
				System.out.println(b[1]-1);
				break;
			} System.out.println(b[1]-1) System.out.println System.out System System.out b[1]-1 b[1] b 1 1 break; String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	}
} Main
import java.util.*;
import java.util.Arrays;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextInt();
		}
		b[0] = 1;
		int now = 1;
		do{
			if(b[a[now-1]-1]==0){
				b[a[now-1]-1]=b[now-1]+1;
				now = a[now-1];
			}else{
				System.out.println(-1);
				break;
			}
			if(now==2){
				System.out.println(b[1]-1);
				break;
			}
		}while(true);
	}
}