import java.util.Arrays;
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];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


    }



} import java.util.Arrays; Arrays java.util 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];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


    }



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

        int n=sc.nextInt();
        int[] a=new int[n];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


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

        int n=sc.nextInt();
        int[] a=new int[n];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


    } 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 int count=0; count 0 int r=1; r 1 boolean aaaa=false; aaaa false 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 while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        } true {
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        } r=a[r-1] r a[r-1] a r-1 r 1 count++ count if(r==2){
                aaaa=true;
                break;
            } r==2 r 2 {
                aaaa=true;
                break;
            } aaaa=true aaaa true break; if(count>n){
                break;
            } count>n count n {
                break;
            } break; if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        } aaaa {
            System.out.println(count);
        } System.out.println(count) System.out.println System.out System System.out count {
            System.out.println("-1");
        } System.out.println("-1") System.out.println System.out System System.out "-1" 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];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


    }



} public class Main {

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

        int n=sc.nextInt();
        int[] a=new int[n];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


    }



} Main
import java.util.Arrays;
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];
        int count=0;
        int r=1;
        boolean aaaa=false;

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

        while(true){
            r=a[r-1];
            count++;
            if(r==2){
                aaaa=true;
                break;
            }
            if(count>n){
                break;
            }
        }

        if(aaaa){
            System.out.println(count);
        }else{
            System.out.println("-1");
        }


    }



}