import java.util.*;

public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	}
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	}
} Main public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = sc.nextInt();
		} {
			arr[i] = sc.nextInt();
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc boolean[] buttons = new boolean[n]; buttons new boolean[n] n int count = 0; count 0 int next = 1; next 1 while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		} true {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		} if (buttons[next - 1]) {
				break;
			} buttons[next - 1] buttons next - 1 next 1 {
				break;
			} break; if (next == 2) {
				System.out.println(count);
				return;
			} next == 2 next 2 {
				System.out.println(count);
				return;
			} System.out.println(count) System.out.println System.out System System.out count return; buttons[next - 1] = true buttons[next - 1] buttons next - 1 next 1 true next = arr[next - 1] next arr[next - 1] arr next - 1 next 1 count++ count 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) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	}
} public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	}
} Main
import java.util.*;

public class Main {
	public static void main (String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
		}
		boolean[] buttons = new boolean[n];
		int count = 0;
		int next = 1;
		while (true) {
			if (buttons[next - 1]) {
				break;
			}
			if (next == 2) {
				System.out.println(count);
				return;
			}
			buttons[next - 1] = true;
			next = arr[next - 1];
			count++;
		}
		System.out.println(-1);
	}
}
