import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int a[]=new int[n]; a new int[n] n for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i]=scan.nextInt();
		} {
			a[i]=scan.nextInt();
		} a[i]=scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan scan.close() scan.close scan int point=1 point 1 cnt=0; cnt 0 int flg=0; flg 0 while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		} true {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		} point=a[point-1] point a[point-1] a point-1 point 1 cnt++ cnt if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break; point==2 point 2 {
				flg=1;
				break;
			} flg=1 flg 1 break; if(cnt>=n)break; cnt>=n cnt n break; System.out.println((flg==1)? cnt:"-1") System.out.println System.out System System.out (flg==1)? cnt:"-1" (flg==1) flg 1 cnt "-1" String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			a[i]=scan.nextInt();
		}
		scan.close();
		int point=1,cnt=0;
		int flg=0;
		while(true) {
			point=a[point-1];
			cnt++;
			if(point==2) {
				flg=1;
				break;
			}else if(cnt>=n)break;
		}
		System.out.println((flg==1)? cnt:"-1");
	}
}