import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  }
} import java.util.*; util.* java public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  }
} Main public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  } main {
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.nextLine()); N Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] a = new int[N]; a new int[N] N for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      a[i] = Integer.parseInt(sc.nextLine());
    } {
      a[i] = Integer.parseInt(sc.nextLine());
    } a[i] = Integer.parseInt(sc.nextLine()) a[i] a i Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int count = 0; count 0 int n = 0; n 0 boolean c = false; c false for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    } {
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    } if(n+1 == 2){
        c = true;
        break;
      } n+1 == 2 n+1 n 1 2 {
        c = true;
        break;
      } c = true c true break; n = a[n] - 1 n a[n] - 1 a[n] a n 1 count++ count if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    } c {
      System.out.println(count);
    } System.out.println(count) System.out.println System.out System System.out count {
      System.out.println(-1);
    } System.out.println(-1) System.out.println System.out System System.out -1 1 String[]args args public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  }
} public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  }
} Main
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    
    int[] a = new int[N];
    for(int i = 0; i < N; i++){
      a[i] = Integer.parseInt(sc.nextLine());
    }
    int count = 0;
    int n = 0;
    boolean c = false;
    for(int i = 0; i < N;i++){
      if(n+1 == 2){
        c = true;
        break;
      }
      n = a[n] - 1;
      count++;
    }
    
    if(c){
      System.out.println(count);
    }else{
      System.out.println(-1);
    }
  }
}