import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  }
  

  
} 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 a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  }
  

  
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-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+1]; a new int[N+1] N+1 N 1 for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    } int i=1; int i=1; i 1 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 answer=0; answer 0 int lightNum=1; lightNum 1 while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    } 1==1 1 1 {
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    } lightNum=a[lightNum] lightNum a[lightNum] a lightNum answer++ answer if(lightNum==2){
        System.out.println(answer);
        return;
      } lightNum==2 lightNum 2 {
        System.out.println(answer);
        return;
      } System.out.println(answer) System.out.println System.out System System.out answer return; if(answer>110000){
        System.out.println(-1);
        return;
      } answer>110000 answer 110000 {
        System.out.println(-1);
        return;
      } System.out.println(-1) System.out.println System.out System System.out -1 1 return; String[] args args public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  }
  

  
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  }
  

  
} Main
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N+1];
    for(int i=1;i<=N;i++){
      a[i]=sc.nextInt();
    }
    int answer=0;
    int lightNum=1;
    while(1==1){
      lightNum=a[lightNum];
      answer++;
      if(lightNum==2){
        System.out.println(answer);
        return;
      }
      if(answer>110000){
        System.out.println(-1);
        return;
      }
    }
      
  }
  

  
}
