
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
			a[i] = Integer.parseInt(sc.next()) - 1;
		} {
			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 int count = 0; count 0 int now = 0; now 0 while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		} true {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		} if (now == 1) {
				System.out.println(count);
				break;
			} now == 1 now 1 {
				System.out.println(count);
				break;
			} System.out.println(count) System.out.println System.out System System.out count break; if (count >= n) {
				System.out.println(-1);
				break;
			} count >= n count n {
				System.out.println(-1);
				break;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 break; count++ count now = a[now] now a[now] a now sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	}
} public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	}
} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = Integer.parseInt(sc.next()) - 1;
		}
		int count = 0;
		int now = 0;
		while (true) {
			if (now == 1) {
				System.out.println(count);
				break;
			}
			if (count >= n) {
				System.out.println(-1);
				break;
			}
			count++;
			now = a[now];
		}
		sc.close();
	}
}