import java.util.*;
public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


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

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


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

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


    } main {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


    } 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<n;i++){
            a[i]=scan.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            a[i]=scan.nextInt();
        } {
            a[i]=scan.nextInt();
        } a[i]=scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan int bot=0; bot 0 int cnt=1; cnt 1 while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        } true {
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        } if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            } a[bot]==2 a[bot] a bot 2 {
                break;
            } break; {
                bot=a[bot]-1;
            } bot=a[bot]-1 bot a[bot]-1 a[bot] a bot 1 if(cnt>n){
                cnt=-1;
                break;
            } cnt>n cnt n {
                cnt=-1;
                break;
            } cnt=-1 cnt -1 1 break; cnt++ cnt System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


    }
} public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


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

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);

        int n=scan.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=scan.nextInt();
        }

        int bot=0;
        int cnt=1;
        while(true){
            if(a[bot]==2){
                break;
            }else{
                bot=a[bot]-1;
            }

            if(cnt>n){
                cnt=-1;
                break;
            }


            cnt++;
        }

        System.out.println(cnt);


    }
}