import java.util.Scanner;

class Main {
    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] = Integer.parseInt(sc.next()) - 1;
        }

        boolean[] b = new boolean[n];
        int i = 0;
        int cnt = 0;

        for ( ; !b[i] && i != 1; ++cnt) {
            b[i] = true;
            i = a[i];
        }

        if (i == 1) {
            System.out.println(cnt);
        } else {
            System.out.println(-1);
        }
    }
} import java.util.Scanner; Scanner java.util class Main {
    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] = Integer.parseInt(sc.next()) - 1;
        }

        boolean[] b = new boolean[n];
        int i = 0;
        int cnt = 0;

        for ( ; !b[i] && i != 1; ++cnt) {
            b[i] = true;
            i = a[i];
        }

        if (i == 1) {
            System.out.println(cnt);
        } else {
            System.out.println(-1);
        }
    }
} Main 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] = Integer.parseInt(sc.next()) - 1;
        }

        boolean[] b = new boolean[n];
        int i = 0;
        int cnt = 0;

        for ( ; !b[i] && i != 1; ++cnt) {
            b[i] = true;
            i = a[i];
        }

        if (i == 1) {
            System.out.println(cnt);
        } else {
            System.out.println(-1);
        }
    } 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] = Integer.parseInt(sc.next()) - 1;
        }

        boolean[] b = new boolean[n];
        int i = 0;
        int cnt = 0;

        for ( ; !b[i] && i != 1; ++cnt) {
            b[i] = true;
            i = a[i];
        }

        if (i == 1) {
            System.out.println(cnt);
        } else {
            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] = Integer.parseInt(sc.next()) - 1;
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            a[i] = Integer.parseInt(sc.next()) - 1;
        } {
            a[i] = Integer.parseInt(sc.next()) - 1;
        } a[i] = Integer.parseInt(sc.next()) - 1 a[i] a i Integer.parseInt(sc.next()) - 1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 boolean[] b = new boolean[n]; b new boolean[n] n int i = 0; i 0 int cnt = 0; cnt 0 for ( ; !b[i] && i != 1; ++cnt) {
            b[i] = true;
            i = a[i];
        } ; !b[i] && i != 1 !b[i] b[i] b i i != 1 i 1 ++cnt ++cnt cnt {
            b[i] = true;
            i = a[i];
        } {
            b[i] = true;
            i = a[i];
        } b[i] = true b[i] b i true i = a[i] i a[i] a i if (i == 1) {
            System.out.println(cnt);
        } else {
            System.out.println(-1);
        } i == 1 i 1 {
            System.out.println(cnt);
        } System.out.println(cnt) System.out.println System.out System System.out cnt {
            System.out.println(-1);
        } System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args
import java.util.Scanner;

class Main {
    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] = Integer.parseInt(sc.next()) - 1;
        }

        boolean[] b = new boolean[n];
        int i = 0;
        int cnt = 0;

        for ( ; !b[i] && i != 1; ++cnt) {
            b[i] = true;
            i = a[i];
        }

        if (i == 1) {
            System.out.println(cnt);
        } else {
            System.out.println(-1);
        }
    }
}