import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] nums=new int[n];
    for(int i=0;i<n;i++){
      nums[i]=sc.nextInt();
    }
    boolean[] turned=new boolean[n];
    turned[0]=true;
    int now=1;
    int turns=0;
    while(true){
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    }
  }
} import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] nums=new int[n];
    for(int i=0;i<n;i++){
      nums[i]=sc.nextInt();
    }
    boolean[] turned=new boolean[n];
    turned[0]=true;
    int now=1;
    int turns=0;
    while(true){
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    }
  }
} Main public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] nums=new int[n];
    for(int i=0;i<n;i++){
      nums[i]=sc.nextInt();
    }
    boolean[] turned=new boolean[n];
    turned[0]=true;
    int now=1;
    int turns=0;
    while(true){
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    }
  } main {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] nums=new int[n];
    for(int i=0;i<n;i++){
      nums[i]=sc.nextInt();
    }
    boolean[] turned=new boolean[n];
    turned[0]=true;
    int now=1;
    int turns=0;
    while(true){
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    }
  } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] nums=new int[n]; nums new int[n] n for(int i=0;i<n;i++){
      nums[i]=sc.nextInt();
    } int i=0; int i=0; i 0 i<n i n i++ i++ i {
      nums[i]=sc.nextInt();
    } {
      nums[i]=sc.nextInt();
    } nums[i]=sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc boolean[] turned=new boolean[n]; turned new boolean[n] n turned[0]=true turned[0] turned 0 true int now=1; now 1 int turns=0; turns 0 while(true){
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    } true {
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    } turns++ turns now=nums[now-1] now nums[now-1] nums now-1 now 1 if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      } turned[now-1] turned now-1 now 1 {
        System.out.println(-1);
        return;
      } System.out.println(-1) System.out.println System.out System System.out -1 1 return; if(now==2){
        System.out.println(turns);
        return;
      } now==2 now 2 {
        System.out.println(turns);
        return;
      } System.out.println(turns) System.out.println System.out System System.out turns return; turned[now-1]=true turned[now-1] turned now-1 now 1 true String[] args args
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] nums=new int[n];
    for(int i=0;i<n;i++){
      nums[i]=sc.nextInt();
    }
    boolean[] turned=new boolean[n];
    turned[0]=true;
    int now=1;
    int turns=0;
    while(true){
      turns++;
      now=nums[now-1];
      if(turned[now-1]){
        System.out.println(-1);
        return;
      }else if(now==2){
        System.out.println(turns);
        return;
      }
      turned[now-1]=true;
    }
  }
}