import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        
        boolean[] visited = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            a[i]--;
        }

        int cnt = 0;
        int i = 0;
        while (!visited[i]) {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        }

        System.out.println(-1);
        return;
    }

} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
} Main public static void main(String[] args) {
        new Solver().run();
    } main {
        new Solver().run();
    } new Solver().run() new Solver().run new Solver() String[] args args class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        
        boolean[] visited = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            a[i]--;
        }

        int cnt = 0;
        int i = 0;
        while (!visited[i]) {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        }

        System.out.println(-1);
        return;
    }

} Solver public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        
        boolean[] visited = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            a[i]--;
        }

        int cnt = 0;
        int i = 0;
        while (!visited[i]) {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        }

        System.out.println(-1);
        return;
    } run {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        
        boolean[] visited = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            a[i]--;
        }

        int cnt = 0;
        int i = 0;
        while (!visited[i]) {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        }

        System.out.println(-1);
        return;
    } 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 boolean[] visited = new boolean[N]; visited new boolean[N] N for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            a[i]--;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = sc.nextInt();
            a[i]--;
        } {
            a[i] = sc.nextInt();
            a[i]--;
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc a[i]-- a[i] a i int cnt = 0; cnt 0 int i = 0; i 0 while (!visited[i]) {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        } !visited[i] visited[i] visited i {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        } visited[i] = true visited[i] visited i true i = a[i] i a[i] a i cnt++ cnt if (i == 1) {
                System.out.println(cnt);
                return;
            } i == 1 i 1 {
                System.out.println(cnt);
                return;
            } System.out.println(cnt) System.out.println System.out System System.out cnt return; System.out.println(-1) System.out.println System.out System System.out -1 1 return;
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        
        boolean[] visited = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            a[i]--;
        }

        int cnt = 0;
        int i = 0;
        while (!visited[i]) {
            // marking i as a visited place.
            visited[i] = true;

            // traversing dependency.
            i = a[i];
            cnt++;
            if (i == 1) {
                System.out.println(cnt);
                return;
            }
        }

        System.out.println(-1);
        return;
    }

}