import java.util.Scanner;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

        System.out.println(-1);
    }

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

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

        System.out.println(-1);
    }

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

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

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

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

        System.out.println(-1);
    } int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = scanner.nextInt() - 1;
        } {
            a[i] = scanner.nextInt() - 1;
        } a[i] = scanner.nextInt() - 1 a[i] a i scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 int index = 0; index 0 int count = 1; count 1 while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        } count < N count N {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        } index = a[index] index a[index] a index if (index == 1) {
                System.out.println(count);
                return;
            } index == 1 index 1 {
                System.out.println(count);
                return;
            } System.out.println(count) System.out.println System.out System System.out count return; count++ count System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

        System.out.println(-1);
    }

} public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

        System.out.println(-1);
    }

} Main
import java.util.Scanner;

public class Main {

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int N = scanner.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int index = 0;
        int count = 1;
        while (count < N) {
            index = a[index];
            if (index == 1) {
                System.out.println(count);
                return;
            }
            count++;
        }

        System.out.println(-1);
    }

}
