import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
} Main public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	} main {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	} try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		} catch(Exception e){
			e.printStackTrace();
		} Exception e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			} int i = 1; int i = 1; i 1 i < N+1 i N+1 N 1 i++ i++ i {
				a[i] = sc.nextInt();
			} {
				a[i] = sc.nextInt();
			} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int result = 0; result 0 int i = 1; i 1 while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			} a[i] != 0 a[i] a i 0 {
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			} if(i == 2){
					a[i] = 0;
					break;
				} i == 2 i 2 {
					a[i] = 0;
					break;
				} a[i] = 0 a[i] a i 0 break; result ++ result int temp = i; temp i i = a[i] i a[i] a i a[temp] = 0 a[temp] a temp 0 if(a[2] != 0){
				result = -1;
			} a[2] != 0 a[2] a 2 0 {
				result = -1;
			} result = -1 result -1 1 System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
} public class Main {

	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		try{
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[] a = new int[N+1];
			for(int i = 1; i < N+1; i++){
				a[i] = sc.nextInt();
			}
			int result = 0;
			int i = 1;
			while(a[i] != 0){
				if(i == 2){
					a[i] = 0;
					break;
				}
				result ++;
				int temp = i;
				i = a[i];
				a[temp] = 0;
			}
			if(a[2] != 0){
				result = -1;
			}
			System.out.println(result);
			
		}catch(Exception e){
			e.printStackTrace();
		}
	}
}