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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  }
} 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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  }
} 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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  } 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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      a[i+1] = sc.nextInt();
    } {
      a[i+1] = sc.nextInt();
    } a[i+1] = sc.nextInt() a[i+1] a i+1 i 1 sc.nextInt() sc.nextInt sc int point =1; point 1 int check =-1; check -1 1 for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    } int i=1; int i=1; i 1 i<N+1 i N+1 N 1 i++ i++ i {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    } {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    } point = a[point] point a[point] a point if (point == 2) {
        check =i;
        break;
      } point == 2 point 2 {
        check =i;
        break;
      } check =i check i break; System.out.println(check) System.out.println System.out System System.out check 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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  }
} 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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  }
} 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=0; i<N; i++) {
      a[i+1] = sc.nextInt();
    }
    int point =1;
    int check =-1;
    for (int i=1; i<N+1; i++) {
      point = a[point];
      if (point == 2) {
        check =i;
        break;
      }
    }
    System.out.println(check);
  }
}