import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	}
} import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	}
} Main @SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner Map<Integer, Integer> map = new HashMap<>(); map new HashMap<>() for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			map.put(i, scanner.nextInt());
		} {
			map.put(i, scanner.nextInt());
		} map.put(i, scanner.nextInt()) map.put map i scanner.nextInt() scanner.nextInt scanner int tmp = 1; tmp 1 int ans = 0; ans 0 for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		} int i = 1; int i = 1; i 1 i <= n + 1 i n + 1 n 1 i++ i++ i {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		} {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		} ans++ ans tmp = map.get(tmp) tmp map.get(tmp) map.get map tmp if (tmp == 2) {
				break;
			} tmp == 2 tmp 2 {
				break;
			} break; if (ans == n + 1) {
				ans = -1;
			} ans == n + 1 ans n + 1 n 1 {
				ans = -1;
			} ans = -1 ans -1 1 System.out.println(ans) System.out.println System.out System System.out ans String args[] args public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	}
} public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	}
} Main
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Map<Integer, Integer> map = new HashMap<>();

		for (int i = 1; i <= n; i++) {
			map.put(i, scanner.nextInt());
		}

		int tmp = 1;
		int ans = 0;
		for (int i = 1; i <= n + 1; i++) {
			ans++;
			tmp = map.get(tmp);
			if (tmp == 2) {
				break;
			}
			if (ans == n + 1) {
				ans = -1;
			}
		}

		System.out.println(ans);
	}
}