import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	}
	
} import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	}
	
} Main public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	} main {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] btn = new int[N]; btn new int[N] N for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i<N i N i++ i++ i {
			btn[i] = sc.nextInt();
		} {
			btn[i] = sc.nextInt();
		} btn[i] = sc.nextInt() btn[i] btn i sc.nextInt() sc.nextInt sc String s = "-1"; s "-1" int count = 0; count 0 int light = btn[0]; light btn[0] btn 0 while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		} true {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		} count++ count if(light == 2) {
			s = count+"";
				break;
			} light == 2 light 2 {
			s = count+"";
				break;
			} s = count+"" s count+"" count "" break; light = btn[light-1] light btn[light-1] btn light-1 light 1 if(count > N) {
				break;
			} count > N count N {
				break;
			} break; System.out.println(s) System.out.println System.out System System.out s String[] args args public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	}
	
} public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	}
	
} Main
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] btn = new int[N];
		for(int i = 0; i<N; i++) {
			btn[i] = sc.nextInt();
		}
		String s = "-1";
		int count = 0;
		int light = btn[0];
		while(true) {
			count++;	
			if(light == 2) {
			s = count+"";
				break;
			}
			light = btn[light-1];
			if(count > N) {
				break;
			}
			
			
		}
		System.out.println(s);
	}
	
}