import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        }
        sc.close();
        int cnt = 0;
        int push = 0;
        while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                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.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        }
        sc.close();
        int cnt = 0;
        int push = 0;
        while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        }
        sc.close();
        int cnt = 0;
        int push = 0;
        while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        }
        sc.close();
        int cnt = 0;
        int push = 0;
        while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.nextLine()); N Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc ArrayList<Integer> a = new ArrayList<>(); a new ArrayList<>() for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            a.add(Integer.parseInt(sc.nextLine())-1);
        } {
            a.add(Integer.parseInt(sc.nextLine())-1);
        } a.add(Integer.parseInt(sc.nextLine())-1) a.add a Integer.parseInt(sc.nextLine())-1 Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc 1 sc.close() sc.close sc int cnt = 0; cnt 0 int push = 0; push 0 while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        } true {
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        } cnt++ cnt push = a.get(push) push a.get(push) a.get a push if (push == 1){
                System.out.println(cnt);
                break;
            } push == 1 push 1 {
                System.out.println(cnt);
                break;
            } System.out.println(cnt) System.out.println System.out System System.out cnt break; if (cnt == N){
                System.out.println(-1);
                break;
            } cnt == N cnt N {
                System.out.println(-1);
                break;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 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.nextLine());
        ArrayList<Integer> a = new ArrayList<>();
        for (int i=0; i<N; i++){
            a.add(Integer.parseInt(sc.nextLine())-1);
        }
        sc.close();
        int cnt = 0;
        int push = 0;
        while (true){
            cnt++;
            push = a.get(push);
            if (push == 1){
                System.out.println(cnt);
                break;
            }
            if (cnt == N){
                System.out.println(-1);
                break;
            }
        }
    }
}