
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int sum = 0; sum 0 int index = 0; index 0 int tmpIndex = 0; tmpIndex 0 int[] a = new int[N]; a new int[N] N for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			a[i] = scan.nextInt();
		} {
			a[i] = scan.nextInt();
		} a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		} true {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		} tmpIndex = index tmpIndex index index = a[index] - 1 index a[index] - 1 a[index] a index 1 a[tmpIndex] = 0 a[tmpIndex] a tmpIndex 0 sum++ sum if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			} index == -1 index -1 1 {
				sum = -1;
				break;
			} sum = -1 sum -1 1 break; if(index == 1) {
				break;
			} index == 1 index 1 {
				break;
			} break; System.out.println(sum) System.out.println System.out System System.out sum scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	}

} Main

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int sum = 0;
		int index = 0;
		int tmpIndex = 0;
		int[] a = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}
		while(true) {
			tmpIndex = index;
			index = a[index] - 1;
			a[tmpIndex] = 0;
			sum++;
			if(index == -1) {
				sum = -1;
				break;
			} else if(index == 1) {
				break;
			}
		}
		System.out.println(sum);
		scan.close();
	}

}
