import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	}

} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	} main {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) ArrayList<Integer> list = new ArrayList(); list new ArrayList() int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int temp = scan.nextInt();
			list.add(temp);
		} {
			int temp = scan.nextInt();
			list.add(temp);
		} int temp = scan.nextInt(); temp scan.nextInt() scan.nextInt scan list.add(temp) list.add list temp if (list.get(0) == 2) {
			System.out.println(1);
			return;
		} list.get(0) == 2 list.get(0) list.get list 0 2 {
			System.out.println(1);
			return;
		} System.out.println(1) System.out.println System.out System System.out 1 return; int index = 1; index 1 int ans = 0; ans 0 for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		} {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		} index = list.get(index - 1) index list.get(index - 1) list.get list index - 1 index 1 ans++ ans if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			} list.get(index - 1) == 2 list.get(index - 1) list.get list index - 1 index 1 2 {
				System.out.println(++ans);
				return;
			} System.out.println(++ans) System.out.println System.out System System.out ++ans ans 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 scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	}

} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	}

} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList();
		int n = scan.nextInt();
		for (int i = 0; i < n; i++) {
			int temp = scan.nextInt();
			list.add(temp);
		}
		if (list.get(0) == 2) {
			System.out.println(1);
			return;
		}
		int index = 1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			index = list.get(index - 1);
			ans++;
			if (list.get(index - 1) == 2) {
				System.out.println(++ans);
				return;
			}
		}
		System.out.println(-1);

	}

}