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];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        System.out.println(cal(0,a,0));

    }
    public static int cal(int i,int[]a,int sum){
        if(a[i]==2) return ++sum;
        if(sum==a.length) return -1;
        sum++;
        return cal(a[i]-1,a,sum);
    }
} 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];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        System.out.println(cal(0,a,0));

    }
    public static int cal(int i,int[]a,int sum){
        if(a[i]==2) return ++sum;
        if(sum==a.length) return -1;
        sum++;
        return cal(a[i]-1,a,sum);
    }
} Main public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        System.out.println(cal(0,a,0));

    } main {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        System.out.println(cal(0,a,0));

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

    }
    public static int cal(int i,int[]a,int sum){
        if(a[i]==2) return ++sum;
        if(sum==a.length) return -1;
        sum++;
        return cal(a[i]-1,a,sum);
    }
} public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        System.out.println(cal(0,a,0));

    }
    public static int cal(int i,int[]a,int sum){
        if(a[i]==2) return ++sum;
        if(sum==a.length) return -1;
        sum++;
        return cal(a[i]-1,a,sum);
    }
} 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];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        
        System.out.println(cal(0,a,0));

    }
    public static int cal(int i,int[]a,int sum){
        if(a[i]==2) return ++sum;
        if(sum==a.length) return -1;
        sum++;
        return cal(a[i]-1,a,sum);
    }
}