
import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    }
} import javax.xml.crypto.Data; Data javax.xml.crypto import java.util.*; util.* java import java.io.*; io.* java public class Main {
    public static void main(String[] args) throws IOException{

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    }
} Main public static void main(String[] args) throws IOException{

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    } main {

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] a = new int[N]; a new int[N] N boolean[] sign = new boolean[N]; sign new boolean[N] N for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = sc.nextInt();
            sign[i] = false;
        } {
            a[i] = sc.nextInt();
            sign[i] = false;
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc sign[i] = false sign[i] sign i false int ans = 0; ans 0 int i = 0; i 0 while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        } true {
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        } if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            } sign[i] sign i {
                System.out.println(-1);
                break;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 break; if(i == 1){
                System.out.println(ans);
                break;
            } i == 1 i 1 {
                System.out.println(ans);
                break;
            } System.out.println(ans) System.out.println System.out System System.out ans break; sign[i] = true sign[i] sign i true i = a[i] - 1 i a[i] - 1 a[i] a i 1 ans++ ans String[] args args public class Main {
    public static void main(String[] args) throws IOException{

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    }
} public class Main {
    public static void main(String[] args) throws IOException{

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    }
} Main

import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{

        //入力
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        boolean[] sign = new boolean[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            sign[i] = false;
        }


        // 出力
        int ans = 0;
        int i = 0;
        while(true){
            if(sign[i]){
                System.out.println(-1);
                break;
            }
            else if(i == 1){
                System.out.println(ans);
                break;
            }
            sign[i] = true;
            i = a[i] - 1;
            ans++;
        }
    }
}