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];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		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];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		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];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		System.out.println(-1);
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		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 for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i] = scanner.nextInt() - 1;
		} {
			a[i] = scanner.nextInt() - 1;
		} a[i] = scanner.nextInt() - 1 a[i] a i scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 int pos = 0; pos 0 for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		} {
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		} pos = a[pos] pos a[pos] a pos if(pos == 1){
				System.out.println(i+1);
				return;
			} pos == 1 pos 1 {
				System.out.println(i+1);
				return;
			} System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 return; 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];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		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];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		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];
		for(int i=0;i<n;i++){
			a[i] = scanner.nextInt() - 1;
		}
		int pos = 0;
		for(int i=0;i<n;i++){
			pos = a[pos];
			if(pos == 1){
				System.out.println(i+1);
				return;
			}
		}
		System.out.println(-1);
	}

}
