import java.util.Scanner;

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

            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);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = sc.nextInt() - 1;
            }
            int pos = 0;
            int ans = -1;
            for (int i = 0; i < N; i++) {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            }

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

            System.out.println(ans);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = sc.nextInt() - 1;
            }
            int pos = 0;
            int ans = -1;
            for (int i = 0; i < N; i++) {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            }

            System.out.println(ans);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = sc.nextInt() - 1;
            }
            int pos = 0;
            int ans = -1;
            for (int i = 0; i < N; i++) {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            }

            System.out.println(ans);
        } sc.hasNextInt() sc.hasNextInt sc {
            int N = sc.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = sc.nextInt() - 1;
            }
            int pos = 0;
            int ans = -1;
            for (int i = 0; i < N; i++) {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            }

            System.out.println(ans);
        } 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 int pos = 0; pos 0 int ans = -1; ans -1 1 for (int i = 0; i < N; i++) {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            } {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            } if (pos == 1) {
                    ans = i;
                    break;
                } pos == 1 pos 1 {
                    ans = i;
                    break;
                } ans = i ans i break; pos = a[pos] pos a[pos] a pos 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);
        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int[] a = new int[N];
            for (int i = 0; i < N; i++) {
                a[i] = sc.nextInt() - 1;
            }
            int pos = 0;
            int ans = -1;
            for (int i = 0; i < N; i++) {
                if (pos == 1) {
                    ans = i;
                    break;
                }
                pos = a[pos];
            }

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

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

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

            System.out.println(ans);
        }
    }
}
