import java.util.*;

public class Main {
    public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    }
} Main public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    } main {
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    } Scanner cin = new Scanner(System.in); cin new Scanner(System.in) int N = cin.nextInt(); N cin.nextInt() cin.nextInt cin int list[] = new int[N]; list new int[N] N for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            list[i] = cin.nextInt();
        } {
            list[i] = cin.nextInt();
        } list[i] = cin.nextInt() list[i] list i cin.nextInt() cin.nextInt cin cin.close() cin.close cin int result = -1; result -1 1 int tmp = 0; tmp 0 for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        } int j=0; int j=0; j 0 j<(int)Math.pow(10,7) j (int)Math.pow(10,7) Math.pow Math 10 7 j++ j++ j {
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        } {
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        } tmp = list[tmp]-1 tmp list[tmp]-1 list[tmp] list tmp 1 if(tmp==1){
                result = j+1;
                break;
            } tmp==1 tmp 1 {
                result = j+1;
                break;
            } result = j+1 result j+1 j 1 break; System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
    public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    }
} public class Main {
    public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args){
        
        Scanner cin = new Scanner(System.in);
        
        int N = cin.nextInt();
        int list[] = new int[N];
        for(int i=0;i<N;i++){
            list[i] = cin.nextInt();
        }
        cin.close();
        int result = -1;
        int tmp = 0;
        for(int j=0;j<(int)Math.pow(10,7);j++){
            tmp = list[tmp]-1;
            if(tmp==1){
                result = j+1;
                break;
            }
        }
        System.out.println(result);
        
    }
}