import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
}
} 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 []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
}
} Main public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
} main {
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int []po=new int[n]; po new int[n] n boolean b=false; b false for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  } int i=0; int i=0; i 0 i<n i n i++ i++ i {
  	po[i]=sc.nextInt();
  } {
  	po[i]=sc.nextInt();
  } po[i]=sc.nextInt() po[i] po i sc.nextInt() sc.nextInt sc int num=0; num 0 int i=0; i 0 for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    } ; i<n i n i++ i++ i {
    	num=po[num]-1;
      if(num==1){b=true;break;}
    } {
    	num=po[num]-1;
      if(num==1){b=true;break;}
    } num=po[num]-1 num po[num]-1 po[num] po num 1 if(num==1){b=true;break;} num==1 num 1 {b=true;break;} b=true b true break; System.out.println(b?i+1:-1) System.out.println System.out System System.out b?i+1:-1 b i+1 i 1 -1 1 String args[] args public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
}
} public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
}
} Main
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
  int n=sc.nextInt();
  int []po=new int[n];
  boolean b=false;
  for(int i=0;i<n;i++){
  	po[i]=sc.nextInt();
  }
    int num=0;
    int i=0;
    for(;i<n;i++){
    	num=po[num]-1;
      if(num==1){b=true;break;}
    }
    System.out.println(b?i+1:-1);
  
}
}
