import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        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();
        }

        System.out.println(solve(N, a));
    }

    private static int solve(int N, int[] a) {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        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();
        }

        System.out.println(solve(N, a));
    }

    private static int solve(int N, int[] a) {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    }
} Main private static final int MOD = 1_000_000_007; MOD 1_000_000_007 private static final String YES = "Yes"; YES "Yes" private static final String NO = "No"; NO "No" public static void main(String[] args) {
        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();
        }

        System.out.println(solve(N, a));
    } main {
        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();
        }

        System.out.println(solve(N, a));
    } 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();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc System.out.println(solve(N, a)) System.out.println System.out System System.out solve(N, a) solve N a String[] args args private static int solve(int N, int[] a) {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    } solve {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    } int current = 1; current 1 for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            current = a[current-1];

            if (current == 2) return i+1;
        } {
            current = a[current-1];

            if (current == 2) return i+1;
        } current = a[current-1] current a[current-1] a current-1 current 1 if (current == 2) return i+1; current == 2 current 2 return i+1; i+1 i 1 return -1; -1 1 int N N int[] a a public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        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();
        }

        System.out.println(solve(N, a));
    }

    private static int solve(int N, int[] a) {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    }
} public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        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();
        }

        System.out.println(solve(N, a));
    }

    private static int solve(int N, int[] a) {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    }
} Main
import java.util.Scanner;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

    public static void main(String[] args) {
        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();
        }

        System.out.println(solve(N, a));
    }

    private static int solve(int N, int[] a) {
        int current = 1;
        for (int i=0; i<N; i++) {
            current = a[current-1];

            if (current == 2) return i+1;
        }

        return -1;
    }
}