import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int sum = 0;
        boolean[] passed = new boolean[N];
        for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        }
        System.out.println(-1);
    }
} import java.util.Scanner; Scanner java.util import java.util.Stack; Stack java.util class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int sum = 0;
        boolean[] passed = new boolean[N];
        for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        }
        System.out.println(-1);
    }
} Main public static void main(String[] args) {
        new Main().compute();
    } main {
        new Main().compute();
    } new Main().compute() new Main().compute new Main() String[] args args void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int sum = 0;
        boolean[] passed = new boolean[N];
        for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        }
        System.out.println(-1);
    } compute {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int sum = 0;
        boolean[] passed = new boolean[N];
        for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        }
        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 for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = sc.nextInt() - 1;
        } {
            a[i] = sc.nextInt() - 1;
        } a[i] = sc.nextInt() - 1 a[i] a i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int sum = 0; sum 0 boolean[] passed = new boolean[N]; passed new boolean[N] N for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        } int i = 0; int i = 0; i 0 !passed[i] passed[i] passed i i = a[i], sum++ i = a[i] i a[i] a i sum++ sum {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        } {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        } passed[i] = true passed[i] passed i true if (i == 1) {
                System.out.println(sum);
                return;
            } i == 1 i 1 {
                System.out.println(sum);
                return;
            } System.out.println(sum) System.out.println System.out System System.out sum return; System.out.println(-1) System.out.println System.out System System.out -1 1
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt() - 1;
        }
        int sum = 0;
        boolean[] passed = new boolean[N];
        for (int i = 0; !passed[i]; i = a[i], sum++) {
            passed[i] = true;
            if (i == 1) {
                System.out.println(sum);
                return;
            }
        }
        System.out.println(-1);
    }
}
