import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int[] button = new int[N+1];
        boolean[] isLighting = new boolean[N+1];
        for(int i=1; i<=N; i++){
            button[i] = Integer.parseInt(sc.next());
        }
        
        
        int num = 1;
        int ans = 0;
        while(true){
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        }
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int[] button = new int[N+1];
        boolean[] isLighting = new boolean[N+1];
        for(int i=1; i<=N; i++){
            button[i] = Integer.parseInt(sc.next());
        }
        
        
        int num = 1;
        int ans = 0;
        while(true){
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int[] button = new int[N+1];
        boolean[] isLighting = new boolean[N+1];
        for(int i=1; i<=N; i++){
            button[i] = Integer.parseInt(sc.next());
        }
        
        
        int num = 1;
        int ans = 0;
        while(true){
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int[] button = new int[N+1];
        boolean[] isLighting = new boolean[N+1];
        for(int i=1; i<=N; i++){
            button[i] = Integer.parseInt(sc.next());
        }
        
        
        int num = 1;
        int ans = 0;
        while(true){
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] button = new int[N+1]; button new int[N+1] N+1 N 1 boolean[] isLighting = new boolean[N+1]; isLighting new boolean[N+1] N+1 N 1 for(int i=1; i<=N; i++){
            button[i] = Integer.parseInt(sc.next());
        } int i=1; int i=1; i 1 i<=N i N i++ i++ i {
            button[i] = Integer.parseInt(sc.next());
        } {
            button[i] = Integer.parseInt(sc.next());
        } button[i] = Integer.parseInt(sc.next()) button[i] button i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int num = 1; num 1 int ans = 0; ans 0 while(true){
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        } true {
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        } if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            } isLighting[num] == true isLighting[num] isLighting num true {
                System.out.println(-1);
                break;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 break; {
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            } isLighting[num] = true isLighting[num] isLighting num true num = button[num] num button[num] button num ans++ ans if(num == 2){
                    System.out.println(ans);
                    break;
                } num == 2 num 2 {
                    System.out.println(ans);
                    break;
                } System.out.println(ans) System.out.println System.out System System.out ans break; String[] args args
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        
        int[] button = new int[N+1];
        boolean[] isLighting = new boolean[N+1];
        for(int i=1; i<=N; i++){
            button[i] = Integer.parseInt(sc.next());
        }
        
        
        int num = 1;
        int ans = 0;
        while(true){
            if(isLighting[num] == true){
                System.out.println(-1);
                break;
            }else{
                isLighting[num] = true;
                num = button[num];
                ans++;
                if(num == 2){
                    System.out.println(ans);
                    break;
                }
            }
        }
    }
}