import java.util.Scanner;

public 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] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util public 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] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    }
} 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] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    } 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() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    } 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 sc.close() sc.close sc int ans = -1; ans -1 1 int count = 0; count 0 int pos = 0; pos 0 for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        } int i = 0; int i = 0; i 0 i < 100000 i 100000 i++ i++ i {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        } {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        } pos = a[pos] pos a[pos] a pos count++ count if (pos == 1) {
                ans = count;
                break;
            } pos == 1 pos 1 {
                ans = count;
                break;
            } ans = count ans count break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public 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] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    }
} public 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] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

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

public 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] = sc.nextInt() - 1;
        }

        sc.close();

        int ans = -1;
        int count = 0;
        int pos = 0;
        for (int i = 0; i < 100000; i++) {
            pos = a[pos];
            count++;
            if (pos == 1) {
                ans = count;
                break;
            }
        }

        System.out.println(ans);
    }
}