import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
} import java.util.*; util.* java import java.math.*; math.* java class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
} Main public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    } main {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    } try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        } catch(Exception e){
            e.printStackTrace();
        } Exception e {
            e.printStackTrace();
        } e.printStackTrace() e.printStackTrace e {
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ArrayList<Integer> list = new ArrayList<>(); list new ArrayList<>() ArrayList<Boolean> boolList = new ArrayList<>(); boolList new ArrayList<>() for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            } {
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            } list.add(Integer.parseInt(sc.next())) list.add list Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc boolList.add(false) boolList.add boolList false int light = 0; light 0 int ans = 0; ans 0 while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            } light != 1 && boolList.get(light) == false light != 1 light 1 boolList.get(light) == false boolList.get(light) boolList.get boolList light false {
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            } boolList.set(light, true) boolList.set boolList light true int newLight = list.get(light) - 1; newLight list.get(light) - 1 list.get(light) list.get list light 1 light = newLight light newLight ans++ ans if(light == 1) System.out.println(ans);
            else System.out.println(-1); light == 1 light 1 System.out.println(ans) System.out.println System.out System System.out ans System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
 
            int n = Integer.parseInt(sc.next());

            ArrayList<Integer> list = new ArrayList<>();
            ArrayList<Boolean> boolList = new ArrayList<>();

            for(int i = 0; i < n; i++){
                list.add(Integer.parseInt(sc.next()));
                boolList.add(false);
            }

            int light = 0;
            int ans = 0;
            while(light != 1 && boolList.get(light) == false){
                boolList.set(light, true);
                int newLight = list.get(light) - 1;
                light = newLight;
                ans++;
            }

            if(light == 1) System.out.println(ans);
            else System.out.println(-1);
 
        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}