import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] list = new int[n]; list new int[n] n for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
          list[i] = sc.nextInt();
        } {
          list[i] = sc.nextInt();
        } list[i] = sc.nextInt() list[i] list i sc.nextInt() sc.nextInt sc int i = 0; i 0 int count = 0; count 0 boolean[] passed = new boolean[n]; passed new boolean[n] n while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        } true {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        } if (i == 1) {
            break;
          } i == 1 i 1 {
            break;
          } break; if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          } !passed[i] passed[i] passed i {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } passed[i] = true passed[i] passed i true i = list[i] - 1 i list[i] - 1 list[i] list i 1 count++ count {
            count = -1;
            break;
          } count = -1 count -1 1 break; System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int n = sc.nextInt();
        int[] list = new int[n];
        for(int i = 0; i < n; i++) {
          list[i] = sc.nextInt();
        }
        int i = 0;
        int count = 0;
        boolean[] passed = new boolean[n];
        while(true) {
          if (i == 1) {
            break;
          }
          if (!passed[i]) {
             passed[i] = true;
             i = list[i] - 1;
             count++;
          } else {
            count = -1;
            break;
          }
        }
    
		// 出力
		System.out.println(count);
	}
}