import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	}
} Main public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	} main {
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int a=scan.nextInt(); a scan.nextInt() scan.nextInt scan int b[]=new int[a]; b new int[a] a int fig=0; fig 0 for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i!=a i a i++ i++ i {
			b[i]=scan.nextInt();
		} {
			b[i]=scan.nextInt();
		} b[i]=scan.nextInt() b[i] b i scan.nextInt() scan.nextInt scan int za=0; za 0 int count=0; count 0 for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		} int i=0; int i=0; i 0 i!=a+1 i a+1 a 1 i++ i++ i {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		} {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		} if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			} b[za]==2 b[za] b za 2 {
				fig=1;
				count=i+1;
				break;
			} fig=1 fig 1 count=i+1 count i+1 i 1 break; za=b[za]-1 za b[za]-1 b[za] b za 1 System.out.println(fig==1?count:-1) System.out.println System.out System System.out fig==1?count:-1 fig==1 fig 1 count -1 1 String[] args args public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	}
} public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b[]=new int[a];
		int fig=0;
		for(int i=0;i!=a;i++) {
			b[i]=scan.nextInt();
		}
		int za=0;
		int count=0;
		for(int i=0;i!=a+1;i++) {
			if(b[za]==2) {
				fig=1;
				count=i+1;
				break;
			}
			za=b[za]-1;
		}
		System.out.println(fig==1?count:-1);
	}
}