import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	}
} 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();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] num = new int[n]; num new int[n] n for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < num.length i num.length num num.length i++ i++ i {
			num[i] = scanner.nextInt();
		} {
			num[i] = scanner.nextInt();
		} num[i] = scanner.nextInt() num[i] num i scanner.nextInt() scanner.nextInt scanner boolean[] check = new boolean[n]; check new boolean[n] n int i = 0; i 0 int count = 0; count 0 while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		} !check[i] check[i] check i {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		} count++ count check[i] = true check[i] check i true i = num[i] - 1 i num[i] - 1 num[i] num i 1 if (i == 1) {
				System.out.println(count);
				System.exit(0);
			} i == 1 i 1 {
				System.out.println(count);
				System.exit(0);
			} System.out.println(count) System.out.println System.out System System.out count System.exit(0) System.exit System 0 System.out.println("-1") System.out.println System.out System System.out "-1" 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();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		for (int i = 0; i < num.length; i++) {
			num[i] = scanner.nextInt();
		}
		boolean[] check = new boolean[n];
		int i = 0;
		int count = 0;
		while (!check[i]) {
			//System.out.println(i);
			count++;
			check[i] = true;
			i = num[i] - 1;
			if (i == 1) {
				System.out.println(count);
				System.exit(0);
			}
		}
		System.out.println("-1");
		scanner.close();
	}
}
