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];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    }
} 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];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int [N];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int [N];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    } 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 boolean [] boo = new boolean[N]; boo new boolean[N] N for(int i=0; i<N; i++)A[i] = sc.nextInt()-1; int i=0; int i=0; i 0 i<N i N i++ i++ i A[i] = sc.nextInt()-1; A[i] = sc.nextInt()-1 A[i] A i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int ans=0; ans 0 int tmp = 0; tmp 0 while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        } tmp!=1 tmp 1 {
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        } tmp = A[tmp] tmp A[tmp] A tmp if(boo[tmp]){
                ans=-1;
                break;
            } boo[tmp] boo tmp {
                ans=-1;
                break;
            } ans=-1 ans -1 1 break; boo[tmp]=true boo[tmp] boo tmp true ans++ ans System.out.println(ans) System.out.println System.out System System.out ans 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];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int [] A = new int [N];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    }
} 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];
        boolean [] boo = new boolean[N];
        for(int i=0; i<N; i++)A[i] = sc.nextInt()-1;
        int ans=0;
        int tmp = 0;
        while(tmp!=1){
            tmp = A[tmp];
            if(boo[tmp]){
                ans=-1;
                break;
            }
            boo[tmp]=true;
            ans++;
        }
        System.out.println(ans);
    }
}
