import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] push = new int[n];
        int index = 0;
        int count = 0;
        boolean ok = false;

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

        for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        }

        System.out.println(ok ? count : -1);
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] push = new int[n];
        int index = 0;
        int count = 0;
        boolean ok = false;

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

        for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        }

        System.out.println(ok ? count : -1);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] push = new int[n];
        int index = 0;
        int count = 0;
        boolean ok = false;

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

        for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        }

        System.out.println(ok ? count : -1);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] push = new int[n];
        int index = 0;
        int count = 0;
        boolean ok = false;

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

        for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        }

        System.out.println(ok ? count : -1);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] push = new int[n]; push new int[n] n int index = 0; index 0 int count = 0; count 0 boolean ok = false; ok false for(int i = 0;i < n;i++){
            push[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            push[i] = sc.nextInt();
        } {
            push[i] = sc.nextInt();
        } push[i] = sc.nextInt() push[i] push i sc.nextInt() sc.nextInt sc for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        } {
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        } index = push[index]-1 index push[index]-1 push[index] push index 1 count++ count if(index == 1){
                ok = true;
                break;
            } index == 1 index 1 {
                ok = true;
                break;
            } ok = true ok true break; System.out.println(ok ? count : -1) System.out.println System.out System System.out ok ? count : -1 ok count -1 1 String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] push = new int[n];
        int index = 0;
        int count = 0;
        boolean ok = false;

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

        for(int i = 0;i < n;i++){
            index = push[index]-1;
            count++;
            if(index == 1){
                ok = true;
                break;
            }
        }

        System.out.println(ok ? count : -1);
    }
}