import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    } main {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] num = new int[N]; num new int[N] N for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            num[i] = scan.nextInt();
        } {
            num[i] = scan.nextInt();
        } num[i] = scan.nextInt() num[i] num i scan.nextInt() scan.nextInt scan boolean[] lightON = new boolean[N]; lightON new boolean[N] N int buttonNum = num[0]; buttonNum num[0] num 0 lightON[0] = true lightON[0] lightON 0 true int count = 0; count 0 int answer = -1; answer -1 1 while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        } true {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        } lightON[buttonNum-1] = true lightON[buttonNum-1] lightON buttonNum-1 buttonNum 1 true count++ count if(lightON[1] == true) {
                answer = count;
                break;
            } lightON[1] == true lightON[1] lightON 1 true {
                answer = count;
                break;
            } answer = count answer count break; buttonNum = num[buttonNum-1] buttonNum num[buttonNum-1] num buttonNum-1 buttonNum 1 if(lightON[buttonNum-1] == true) {
                break; 
            } lightON[buttonNum-1] == true lightON[buttonNum-1] lightON buttonNum-1 buttonNum 1 true {
                break; 
            } break; System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    }
}
