import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
    /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.nio.charset.StandardCharsets; StandardCharsets java.nio.charset import java.util.*; util.* java public class Main {
    /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
}

} Main /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    } main {
        new Main().run();
    } new Main().run() new Main().run new Main() String[] args args void run(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
} run {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] array = new int[N]; array new int[N] N for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int count = 1; count 1 int next = 0; next 0 if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    } array[0] == 2 array[0] array 0 2 System.out.println(1) System.out.println System.out System System.out 1 {
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    } while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        } true {
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        } count++ count next = array[next]-1 next array[next]-1 array[next] array next 1 if(array[next] == 2){
                System.out.println(count);
                break;
            } array[next] == 2 array[next] array next 2 {
                System.out.println(count);
                break;
            } System.out.println(count) System.out.println System.out System System.out count break; if(count >= N){
                System.out.println(-1);
                break;
            } count >= N count N {
                System.out.println(-1);
                break;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 break; public class Main {
    /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
}

} public class Main {
    /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
    /**
     * Iterate through each line of input.
     */

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] array = new int[N];

        for(int i=0; i<N; i++){
            array[i] = sc.nextInt();
        }

        int count = 1;
        int next = 0;
if(array[0] == 2) System.out.println(1);
else{
        while(true){
            count++;
            next = array[next]-1;
            if(array[next] == 2){
                System.out.println(count);
                break;
            }

            if(count >= N){
                System.out.println(-1);
                break;
            }
        }
    }
}

}
