import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	}
} Main public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	} main {
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter ou = new PrintWriter(System.out); ou new PrintWriter(System.out) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n]; a new int[n] n for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1; int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i a[i] = Integer.parseInt(sc.next()) - 1; a[i] = Integer.parseInt(sc.next()) - 1 a[i] a i Integer.parseInt(sc.next()) - 1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 sc.close() sc.close sc boolean[] q = new boolean[n]; q new boolean[n] n Arrays.fill(q , false) Arrays.fill Arrays q false q[0] = true q[0] q 0 true int now = 0; now 0 for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
			q[now] = true;
			now = a[now];
		} {
			q[now] = true;
			now = a[now];
		} q[now] = true q[now] q now true now = a[now] now a[now] a now if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		} !q[1] q[1] q 1 ou.println(-1) ou.println ou -1 1 {
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		} int cou = 0; cou 0 Arrays.fill(q , false) Arrays.fill Arrays q false now = 0 now 0 while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			} !q[1] q[1] q 1 {
				cou++;
				now = a[now];
				q[now] = true;
			} cou++ cou now = a[now] now a[now] a now q[now] = true q[now] q now true ou.println(cou) ou.println ou cou ou.flush() ou.flush ou String[]args args public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	}
} public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	}
} Main
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++) a[i] = Integer.parseInt(sc.next()) - 1;
		sc.close();
		boolean[] q = new boolean[n];
		Arrays.fill(q , false);
		q[0] = true;
		int now = 0;
		for(int i = 0 ; i < n ; i++){
			q[now] = true;
			now = a[now];
		}
		if(!q[1]) ou.println(-1);
		else{
			int cou = 0;
			Arrays.fill(q , false);
			now = 0;
			while(!q[1]){
				cou++;
				now = a[now];
				q[now] = true;
			}
			ou.println(cou);
		}
		ou.flush();
	}
}