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