import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n+1]; a new int[n+1] n+1 n 1 for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc boolean[] reachable = new boolean[n+1]; reachable new boolean[n+1] n+1 n 1 int cur = 1; cur 1 int hops = 0; hops 0 while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		} !reachable[cur] && cur != 2 !reachable[cur] reachable[cur] reachable cur cur != 2 cur 2 {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		} reachable[cur] = true reachable[cur] reachable cur true cur = a[cur] cur a[cur] a cur hops++ hops reachable[cur] = true reachable[cur] reachable cur true System.out.println(reachable[2] ? hops : -1) System.out.println System.out System System.out reachable[2] ? hops : -1 reachable[2] reachable 2 hops -1 1 sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n+1];
		for (int i=1; i<=n; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] reachable = new boolean[n+1];
		int cur = 1;
		int hops = 0;
		while(!reachable[cur] && cur != 2) {
			reachable[cur] = true;
			cur = a[cur];
			hops++;
		}
		reachable[cur] = true;
		System.out.println(reachable[2] ? hops : -1);
		sc.close();
	}

}
