import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    }
} Main public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    } main {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    } int s=1; s 1 int p=0; p 0 Scanner scan= new Scanner(System.in); scan new Scanner(System.in) int n=scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a=new int[n]; a new int[n] n for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        } int i = 0; int i = 0; i 0 i <a.length i a.length a a.length i++ i++ i {
            a[i]=scan.nextInt();
        } {
            a[i]=scan.nextInt();
        } a[i]=scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        } s!=2 s 2 {
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        } s=a[s-1] s a[s-1] a s-1 s 1 p++ p if (p>=a.length){
                p=-1;
                break;
            } p>=a.length p a.length a a.length {
                p=-1;
                break;
            } p=-1 p -1 1 break; System.out.println(p) System.out.println System.out System System.out p String[] args args public class Main {
    public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    }
} public class Main {
    public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int s=1;
        int p=0;
        Scanner scan= new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n];
        for (int i = 0; i <a.length ; i++) {
            a[i]=scan.nextInt();
        }
        while (s!=2){
            s=a[s-1];
            p++;

            if (p>=a.length){
                p=-1;
                break;
            }
        }
        System.out.println(p);
    }
}
