import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	}
} import java.util.*; util.* java public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] num = new int[N+1]; num new int[N+1] N+1 N 1 for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			num[i] = sc.nextInt();
		} {
			num[i] = sc.nextInt();
		} num[i] = sc.nextInt() num[i] num i sc.nextInt() sc.nextInt sc int number = 1; number 1 int count = 0; count 0 boolean key = false; key false for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		} int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		} {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		} int tmp = num[number]; tmp num[number] num number if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			} tmp == -1 tmp -1 1 {
				System.out.println(-1);
				System.exit(0);
			} System.out.println(-1) System.out.println System.out System System.out -1 1 System.exit(0) System.exit System 0 num[number] = -1 num[number] num number -1 1 number = tmp number tmp count++ count if (number == 2) {
				key = true;
				break;
			} number == 2 number 2 {
				key = true;
				break;
			} key = true key true break; System.out.println(true?count:-1) System.out.println System.out System System.out true?count:-1 true count -1 1 String[] args args public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	}
} public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	}
} Main
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] num = new int[N+1];
		for (int i = 1; i <= N; i++) {
			num[i] = sc.nextInt();
		}
		int number = 1;
		int count = 0;
		boolean key = false;
		for (int i = 1; i <= N; i++) {
			int tmp = num[number];
			if (tmp == -1) {
				System.out.println(-1);
				System.exit(0);
			}
			num[number] = -1;
			number = tmp;
			count++;
			if (number == 2) {
				key = true;
				break;
			}
		}
		System.out.println(true?count:-1);
	}
}