import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer a[]  = new Integer[n + 100];
    for (int i = 1; i <= n; i++) {
      a[i]  = sc.nextInt();
    }
    int index = 1;
    int num = 0;
    while(true){
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    }

  }
} import java.io.*; io.* java import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer a[]  = new Integer[n + 100];
    for (int i = 1; i <= n; i++) {
      a[i]  = sc.nextInt();
    }
    int index = 1;
    int num = 0;
    while(true){
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    }

  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer a[]  = new Integer[n + 100];
    for (int i = 1; i <= n; i++) {
      a[i]  = sc.nextInt();
    }
    int index = 1;
    int num = 0;
    while(true){
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    }

  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer a[]  = new Integer[n + 100];
    for (int i = 1; i <= n; i++) {
      a[i]  = sc.nextInt();
    }
    int index = 1;
    int num = 0;
    while(true){
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    }

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc Integer a[]  = new Integer[n + 100]; a new Integer[n + 100] n + 100 n 100 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 index = 1; index 1 int num = 0; num 0 while(true){
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    } true {
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    } num++ num if(a[index] == 2){
        System.out.println(num);
        return;
      } a[index] == 2 a[index] a index 2 {
        System.out.println(num);
        return;
      } System.out.println(num) System.out.println System.out System System.out num return; if(num > n){
        System.out.println(-1);
        return;
      } num > n num n {
        System.out.println(-1);
        return;
      } System.out.println(-1) System.out.println System.out System System.out -1 1 return; index = a[index] index a[index] a index String[] args args
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    Integer a[]  = new Integer[n + 100];
    for (int i = 1; i <= n; i++) {
      a[i]  = sc.nextInt();
    }
    int index = 1;
    int num = 0;
    while(true){
      num++;

      if(a[index] == 2){
        System.out.println(num);
        return;
      }
     
      if(num > n){
        System.out.println(-1);
        return;
      }
      index = a[index];
    }

  }
}
