import 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    }
} import java.util.*; util.* java 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    }
} 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    } 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    } 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 boolean[] visited = new boolean[n]; visited new boolean[n] n int count = 0; count 0 int cur = 0; cur 0 visited[cur] = true visited[cur] visited cur true while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        } true {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        } ++count count int next = a[cur]; next a[cur] a cur if (visited[next]) {
                System.out.println(-1);
                return;
            } visited[next] visited next {
                System.out.println(-1);
                return;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 return; if (next == 1) {
                System.out.println(count);
                return;
            } next == 1 next 1 {
                System.out.println(count);
                return;
            } System.out.println(count) System.out.println System.out System System.out count return; visited[next] = true visited[next] visited next true cur = next cur next 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    }
} 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    }
} Main
import 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;
        }
        boolean[] visited = new boolean[n];
        int count = 0;
        int cur = 0;
        visited[cur] = true;
        while (true) {
            ++count;
            int next = a[cur];
            if (visited[next]) {
                System.out.println(-1);
                return;
            }
            if (next == 1) {
                System.out.println(count);
                return;
            }

            visited[next] = true;
            cur = next;
        }
    }
}