import java.util.Scanner;
	public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		}
		} import java.util.Scanner; Scanner java.util public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		}
		} Main public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		} main {   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] a = new int[N]; a new int[N] N int count = 0; count 0 int v = 1; v 1 int flg = 0; flg 0 for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			    	a[i] = scanner.nextInt();
			    } {
			    	a[i] = scanner.nextInt();
			    } a[i] = scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    } {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    } v = a[v-1] v a[v-1] a v-1 v 1 count ++ count if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	} v == 2 v 2 {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	} System.out.println(count) System.out.println System.out System System.out count count = 0 count 0 break; if (count == N) {
			    	System.out.println(-1);
			    } count == N count N {
			    	System.out.println(-1);
			    } System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		}
		} public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		}
		} Main
import java.util.Scanner;
	public class Main
		{ public static void main(String[] args)
			{   
			    Scanner scanner = new Scanner(System.in);
			    int N = scanner.nextInt();
			    int[] a = new int[N];
			    int count = 0;
			    int v = 1;
			    int flg = 0;
			    
			    for (int i = 0; i < N; i++) {
			    	a[i] = scanner.nextInt();
			    } 
			    
			    for (int i = 0; i < N; i++) {
			    	v = a[v-1];
			    	
			    	count ++;
			    	if (v == 2) {
			    		System.out.println(count);
			    		count = 0;
			    		break;
			    	}
			    	
			    }
			    
			    if (count == N) {
			    	System.out.println(-1);
			    }
		}
		}