import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x=1 x 1 c=0; c 0 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 a[0]=0 a[0] a 0 0 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 for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		} ; {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		} {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		} if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			} a[x]==2 a[x] a x 2 {
				c++;
				break;
			} c++ c break; if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			} N<c N c {
				c=-1;
				break;
			} c=-1 c -1 1 break; {
				c++;
				x=a[x];
			} c++ c x=a[x] x a[x] a x System.out.print(c) System.out.print System.out System System.out c sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x=1,c=0;
		int N = sc.nextInt();
		int[] a = new int [N+1];
		a[0]=0;
		for(int i=1;i<=N;i++) {
			a[i]=sc.nextInt();
		}
		for(;;) {
			if(a[x]==2) {
				c++;
				break;
			}
			else if(N<c) {
				c=-1;
				break;
			}
			else {
				c++;
				x=a[x];
			}
		}
		System.out.print(c);
		sc.close();
	}
}