import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	}
} Main public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] a = new int[n]; a new int[n] n for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		} int i=0; int i=0; i 0 i < n i n i++ i++ i {
			a[i] = scanner.nextInt();
		} {
			a[i] = scanner.nextInt();
		} a[i] = scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner int val = a[0]; val a[0] a 0 int now = 0; now 0 int count = 1; count 1 while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		} true {
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		} if(val == 2){
				System.out.println(count);
				break;
			} val == 2 val 2 {
				System.out.println(count);
				break;
			} System.out.println(count) System.out.println System.out System System.out count break; now = val -1 now val -1 val 1 val = a[val-1] val a[val-1] a val-1 val 1 a[now] = -1 a[now] a now -1 1 count++ count if(val == -1){
				System.out.println(-1);
				break;
			} val == -1 val -1 1 {
				System.out.println(-1);
				break;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 break; String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for(int i=0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		int val = a[0];
		int now = 0;
		int count = 1;
		while(true){
			if(val == 2){
				System.out.println(count);
				break;
			}
			now = val -1;
			val = a[val-1];
			a[now] = -1;
			count++;
			if(val == -1){
				System.out.println(-1);
				break;
			}
		}
	}
}
