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];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      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[] a = new int[n+1];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n+1];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n+1];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    }
  } 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 boolean[] b = new boolean[n+1]; b new boolean[n+1] n+1 n 1 for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    } int i = 1; int i = 1; i 1 i < n+1 i n+1 n 1 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 i = 1 i 1 count = 0; count 0 while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    } true {
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    } if(i == 2){
        System.out.println(count);
        break;
      } i == 2 i 2 {
        System.out.println(count);
        break;
      } System.out.println(count) System.out.println System.out System System.out count break; if(b[i]){
        System.out.println(-1);
        break;
      } b[i] b i {
        System.out.println(-1);
        break;
      } System.out.println(-1) System.out.println System.out System System.out -1 1 break; b[i] = true b[i] b i true i = a[i] i a[i] a i count++ count 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];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    }
  }
} 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];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      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[] a = new int[n+1];
    boolean[] b = new boolean[n+1];
    for(int i = 1; i < n+1; i++){
      a[i] =sc.nextInt();
    }
    int i = 1,count = 0;
    while(true){
      if(i == 2){
        System.out.println(count);
        break;
      }
      if(b[i]){
        System.out.println(-1);
        break;
      }
      b[i] = true;
      i = a[i];
      count++;
    }
  }
}
