import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	}
} import java.util.*; util.* java public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	} main {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	} int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 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[] dist = new boolean[N]; dist new boolean[N] N int btn = 0; btn 0 int ans = -1; ans -1 1 int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		} {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		} if (dist[btn]) break; dist[btn] dist btn break; dist[btn] = true dist[btn] dist btn true if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			} a[btn] == 2 a[btn] a btn 2 {
				ans = cnt + 1;
				break;
			} ans = cnt + 1 ans cnt + 1 cnt 1 break; btn = a[btn] - 1 btn a[btn] - 1 a[btn] a btn 1 cnt++ cnt System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	}
} public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	}
} Main
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		boolean[] dist = new boolean[N];

		int btn = 0;
		int ans = -1;
		int cnt = 0;
		for (int i = 0; i < N; i++) {
			if (dist[btn]) break;
			dist[btn] = true;
			
			if (a[btn] == 2) {
				ans = cnt + 1;
				break;
			}
			btn = a[btn] - 1;
			cnt++;
		}
		
		System.out.println(ans);
	}
}
