import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	}
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner boolean[] visits = new boolean[100000]; visits new boolean[100000] 100000 Arrays.fill(visits, false) Arrays.fill Arrays visits false int[] buttons = new int[n]; buttons new int[n] n for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < buttons.length i buttons.length buttons buttons.length i++ i++ i {
			buttons[i] = scanner.nextInt();
		} {
			buttons[i] = scanner.nextInt();
		} buttons[i] = scanner.nextInt() buttons[i] buttons i scanner.nextInt() scanner.nextInt scanner int now = 0; now 0 int ans = 0; ans 0 while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		} true {
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		} ans++ ans if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			} visits[now] visits now {
				ans = -1;
				break;
			} ans = -1 ans -1 1 break; {
				visits[now] = true;
			} visits[now] = true visits[now] visits now true now = buttons[now]-1 now buttons[now]-1 buttons[now] buttons now 1 if (now==1) {
				break;
			} now==1 now 1 {
				break;
			} break; System.out.println(ans) System.out.println System.out System System.out ans scanner.close() scanner.close scanner String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	}
} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		
		boolean[] visits = new boolean[100000];
		Arrays.fill(visits, false);
	
		int[] buttons = new int[n];
		for (int i = 0; i < buttons.length; i++) {
			buttons[i] = scanner.nextInt();
		}
		
		int now = 0;
		int ans = 0;
		while(true){
			ans++;
			if (visits[now]) {
				ans = -1;
				break;
			}else {
				visits[now] = true;
			}
			now = buttons[now]-1;
			if (now==1) {
				break;
			}
		}
		
		System.out.println(ans);
		
		
		
		
		scanner.close();
	}
}