import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt() ;

        int[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : 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[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : count);

    }

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

        int[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : count);

    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt() ;

        int[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : count);

    } 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[] pushFlg = new boolean[N]; pushFlg new boolean[N] N for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int lightButton = 1; lightButton 1 boolean relightFlg = false ; relightFlg false int count = 0; count 0 while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        } !relightFlg relightFlg {
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        } if (lightButton == 2) {
                break;
            } lightButton == 2 lightButton 2 {
                break;
            } break; pushFlg[lightButton - 1] = true pushFlg[lightButton - 1] pushFlg lightButton - 1 lightButton 1 true lightButton = a[lightButton - 1] lightButton a[lightButton - 1] a lightButton - 1 lightButton 1 count ++ count if(pushFlg[lightButton - 1]){
                relightFlg = true;
            } pushFlg[lightButton - 1] pushFlg lightButton - 1 lightButton 1 {
                relightFlg = true;
            } relightFlg = true relightFlg true System.out.println(relightFlg ? -1 : count) System.out.println System.out System System.out relightFlg ? -1 : count relightFlg -1 1 count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt() ;

        int[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : count);

    }

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

        int[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : 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[] a = new int[N];
        boolean[] pushFlg = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
        }
        int lightButton = 1;
        boolean relightFlg = false ;
        int count = 0;
        while(!relightFlg){
            if (lightButton == 2) {
                break;
            }
            pushFlg[lightButton - 1] = true;
            lightButton = a[lightButton - 1];
            count ++;
            if(pushFlg[lightButton - 1]){
                relightFlg = true;
            }
        }
        System.out.println(relightFlg ? -1 : count);

    }

}
