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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    }
} 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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    }
} 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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    } 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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length ++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 System.out.println(solve(a)) System.out.println System.out System System.out solve(a) solve a sc.close() sc.close sc String[] args args static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    } solve {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    } boolean[] visited = new boolean[a.length]; visited new boolean[a.length] a.length a a.length visited[0] = true visited[0] visited 0 true int index = 0; index 0 for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        } int step = 1; int step = 1; step 1 ++step ++step step {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        } {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        } index = a[index] index a[index] a index if (index == 1) {
                return step;
            } index == 1 index 1 {
                return step;
            } return step; step if (visited[index]) {
                return -1;
            } visited[index] visited index {
                return -1;
            } return -1; -1 1 visited[index] = true visited[index] visited index true int[] a a 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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    }
} 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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    }
} 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 < a.length; ++i) {
            a[i] = sc.nextInt() - 1;
        }

        System.out.println(solve(a));

        sc.close();
    }

    static int solve(int[] a) {
        boolean[] visited = new boolean[a.length];
        visited[0] = true;
        int index = 0;
        for (int step = 1;; ++step) {
            index = a[index];
            if (index == 1) {
                return step;
            }
            if (visited[index]) {
                return -1;
            }

            visited[index] = true;
        }
    }
}