import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

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

    int j = 0;
    int cnt = 0;
    int pre;
    while(true){
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    }

	}

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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

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

    int j = 0;
    int cnt = 0;
    int pre;
    while(true){
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    }

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

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

    int j = 0;
    int cnt = 0;
    int pre;
    while(true){
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    }

	} main {
		Scanner sc = new Scanner(System.in);

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

    int j = 0;
    int cnt = 0;
    int pre;
    while(true){
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    }

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for(int i=0; i<n; i++){
      a[i] = sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      a[i] = sc.nextInt();
    } {
      a[i] = sc.nextInt();
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int j = 0; j 0 int cnt = 0; cnt 0 int pre; pre while(true){
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    } true {
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    } if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      } a[j] != -1 && a[j] - 1 != j a[j] != -1 a[j] a j -1 1 a[j] - 1 != j a[j] - 1 a[j] a j 1 j {
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      } pre = j pre j j = a[j] - 1 j a[j] - 1 a[j] a j 1 a[pre] = -1 a[pre] a pre -1 1 cnt++ cnt if(j==1){
          System.out.print(cnt);
          return;
        } j==1 j 1 {
          System.out.print(cnt);
          return;
        } System.out.print(cnt) System.out.print System.out System System.out cnt return; {
        System.out.print("-1");
        return;
      } System.out.print("-1") System.out.print System.out System System.out "-1" return; String[] args args
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

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

    int j = 0;
    int cnt = 0;
    int pre;
    while(true){
      if(a[j] != -1 && a[j] - 1 != j){
        pre = j;
        j = a[j] - 1;
        a[pre] = -1;
        cnt++;
        if(j==1){
          System.out.print(cnt);
          return;
        }
      }else{
        System.out.print("-1");
        return;
      }
    }

	}

}
