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 + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	}
} 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 + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	}
} 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 + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	} main {

		int n = sc.nextInt();
		int[] a = new int[n + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	} 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 int flag = 1; flag 1 int count = 0; count 0 for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		} int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		} int i = 1; int i = 1; i 1 i < n + 1 i n + 1 n 1 i++ i++ i {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		} {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		} if (flag == 2) {
				break;
			} flag == 2 flag 2 {
				break;
			} break; flag = a[flag] flag a[flag] a flag count++ count if (flag != 2) {
			count = -1;
		} flag != 2 flag 2 {
			count = -1;
		} count = -1 count -1 1 System.out.println(count) System.out.println System.out System System.out count 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 + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	}
} 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 + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	}
} 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 + 1];
		//a[0] =0;
		int flag = 1;
		int count = 0;

		for (int i = 1; i < n + 1; i++) {
			a[i] = sc.nextInt();
		}

		for (int i = 1; i < n + 1; i++) {
			if (flag == 2) {
				break;
			}
			flag = a[flag];
			count++;
		}
		if (flag != 2) {
			count = -1;
		}
		System.out.println(count);

	}
}