import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] button = new int[n+1]; button new int[n+1] n+1 n 1 for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            button[i] = sc.nextInt();
        } {
            button[i] = sc.nextInt();
        } button[i] = sc.nextInt() button[i] button i sc.nextInt() sc.nextInt sc sc.close() sc.close sc int count = 0; count 0 int nextButton = 1; nextButton 1 boolean success = false; success false for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        } {
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        } count++ count nextButton = button[nextButton] nextButton button[nextButton] button nextButton if(nextButton == 2){
                success = true;
                break;
            } nextButton == 2 nextButton 2 {
                success = true;
                break;
            } success = true success true break; if(!success){
            count = -1;
        } !success success {
            count = -1;
        } count = -1 count -1 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] button = new int[n+1];
        for(int i = 1; i <= n; i++){
            button[i] = sc.nextInt();
        }
        sc.close();

        int count = 0;
        int nextButton = 1;
        boolean success = false;
        for(int j = 0; j < n; j++){
            count++;
            nextButton = button[nextButton];
            if(nextButton == 2){
                success = true;
                break;
            }
        }
        if(!success){
            count = -1;
        }
        System.out.println(count);
    }

}