import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        }
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc int[] b = new int[a]; b new int[a] a for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i<a i a i++ i++ i {
            b[i] = sc.nextInt();
        } {
            b[i] = sc.nextInt();
        } b[i] = sc.nextInt() b[i] b i sc.nextInt() sc.nextInt sc int go = b[0]; go b[0] b 0 int flag = 0; flag 0 int count = 0; count 0 for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        } int i = 0; int i = 0; i 0 i<a i a i++ i++ i {
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        } {
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        } ++count count if(go == 2){
                flag = 1;
                break;
            } go == 2 go 2 {
                flag = 1;
                break;
            } flag = 1 flag 1 break; go = b[go-1] go b[go-1] b go-1 go 1 if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        } flag == 1 flag 1 {
            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 1 String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            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 a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        }
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        sc.nextLine();
        int[] b = new int[a];
        for(int i = 0;i<a;i++){
            b[i] = sc.nextInt();
        }
        int go = b[0];
        int flag = 0;
        int count = 0;
        for(int i = 0;i<a;i++){
            ++count;
            if(go == 2){
                flag = 1;
                break;
            }
            go = b[go-1];
        }
        if(flag == 1){
            System.out.println(count);
        }else{
            System.out.println(-1);
        }
    }
}