import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    } try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        } {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        } Scanner in = new Scanner(System.in) Scanner in = new Scanner(System.in) new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                a[i] = in.nextInt() - 1;
            } {
                a[i] = in.nextInt() - 1;
            } a[i] = in.nextInt() - 1 a[i] a i in.nextInt() - 1 in.nextInt() in.nextInt in 1 int current = 0; current 0 for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            } {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            } current = a[current] current a[current] a current if (current == 1) {
                    System.out.println(i);
                    return;
                } current == 1 current 1 {
                    System.out.println(i);
                    return;
                } System.out.println(i) System.out.println System.out System System.out i return; 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) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = in.nextInt() - 1;
            }

            int current = 0;
            for (int i = 1; i <= N; i++) {
                current = a[current];
                if (current == 1) {
                    System.out.println(i);
                    return;
                }
            }

            System.out.println(-1);
        }
    }
}
