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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int now = 0;
		boolean[] isVisit = new boolean[N];
		Arrays.fill(isVisit, false);
		int ans = 0;
		while(true) {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		}
		System.out.println((now == 1) ? ans : -1);
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int now = 0;
		boolean[] isVisit = new boolean[N];
		Arrays.fill(isVisit, false);
		int ans = 0;
		while(true) {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		}
		System.out.println((now == 1) ? ans : -1);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int now = 0;
		boolean[] isVisit = new boolean[N];
		Arrays.fill(isVisit, false);
		int ans = 0;
		while(true) {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		}
		System.out.println((now == 1) ? ans : -1);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int now = 0;
		boolean[] isVisit = new boolean[N];
		Arrays.fill(isVisit, false);
		int ans = 0;
		while(true) {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		}
		System.out.println((now == 1) ? ans : -1);
	} 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]; a new int[N] N for(int i = 0; i < N; i++) a[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < N i N i++ i++ i a[i] = sc.nextInt(); a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int now = 0; now 0 boolean[] isVisit = new boolean[N]; isVisit new boolean[N] N Arrays.fill(isVisit, false) Arrays.fill Arrays isVisit false int ans = 0; ans 0 while(true) {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		} true {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		} if(now == 1) break; now == 1 now 1 break; if(isVisit[now]) break; isVisit[now] isVisit now break; isVisit[now] = true isVisit[now] isVisit now true now = a[now] - 1 now a[now] - 1 a[now] a now 1 ans++ ans System.out.println((now == 1) ? ans : -1) System.out.println System.out System System.out (now == 1) ? ans : -1 (now == 1) now 1 ans -1 1 String[] args args
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++) a[i] = sc.nextInt();
		int now = 0;
		boolean[] isVisit = new boolean[N];
		Arrays.fill(isVisit, false);
		int ans = 0;
		while(true) {
			if(now == 1) break;
			if(isVisit[now]) break;
			isVisit[now] = true;
			now = a[now] - 1;
			ans++;
		}
		System.out.println((now == 1) ? ans : -1);
	}
}