import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static int check(int[] list) {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {

	public static int check(int[] list) {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	}
} Main public static int check(int[] list) {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	} check {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	} boolean[] leached = new boolean[list.length]; leached new boolean[list.length] list.length list list.length Arrays.fill(leached, false) Arrays.fill Arrays leached false int count=0; count 0 int current=0; current 0 while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		} !leached[current] leached[current] leached current {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		} count++ count leached[current]=true leached[current] leached current true current=list[current] current list[current] list current if(current==1)
				return count; current==1 current 1 return count; count return -1; -1 1 int[] list list public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] buttons_light=new int[n]; buttons_light new int[n] n for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1; int i=0; int i=0; i 0 i<n i n i++ i++ i buttons_light[i]=sc.nextInt()-1; buttons_light[i]=sc.nextInt()-1 buttons_light[i] buttons_light i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 sc.close() sc.close sc System.out.println(check(buttons_light)) System.out.println System.out System System.out check(buttons_light) check buttons_light String[] args args public class Main {

	public static int check(int[] list) {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	}
} public class Main {

	public static int check(int[] list) {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static int check(int[] list) {
		boolean[] leached = new boolean[list.length];
		Arrays.fill(leached, false);
		int count=0;
		int current=0;
		while(!leached[current]) {
			// push button
			count++;
			leached[current]=true;
			current=list[current];
			if(current==1)
				return count;
		}
		return -1;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] buttons_light=new int[n];
		for(int i=0; i<n; i++)
			buttons_light[i]=sc.nextInt()-1;
		sc.close();

		System.out.println(check(buttons_light));
	}
}
