import java.util.*;

public class Main {

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

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    }

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

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

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    }

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

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    } main {
        Scanner sc = new Scanner(System.in);

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc boolean[] visit = new boolean[n]; visit new boolean[n] n int current = 0; current 0 int count = 0; count 0 visit[1] = true visit[1] visit 1 true while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        } true {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        } current = array[current] - 1 current array[current] - 1 array[current] array current 1 count++ count if (current == 1) {
                System.out.println(count);
                return;
            } current == 1 current 1 {
                System.out.println(count);
                return;
            } System.out.println(count) System.out.println System.out System System.out count return; if (visit[current]) {
                System.out.println("-1");
                return;
            } visit[current] visit current {
                System.out.println("-1");
                return;
            } System.out.println("-1") System.out.println System.out System System.out "-1" return; visit[current] = true visit[current] visit current true String[] args args public class Main {

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

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    }

} public class Main {

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

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    }

} Main
import java.util.*;

public class Main {

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

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

        boolean[] visit = new boolean[n];

        int current = 0;
        int count = 0;

        visit[1] = true;

        //ボタンを押す
        while (true) {
            current = array[current] - 1;
            count++;
            if (current == 1) {
                System.out.println(count);
                return;
            }
            if (visit[current]) {
                System.out.println("-1");
                return;
            }
            visit[current] = true;
        }
    }

}