import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        }

        boolean[] used = new boolean[n];
        int i = 0;
        int cnt = 0;
        while (true) {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        }
    }
} import java.util.*; util.* java class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        }

        boolean[] used = new boolean[n];
        int i = 0;
        int cnt = 0;
        while (true) {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        }

        boolean[] used = new boolean[n];
        int i = 0;
        int cnt = 0;
        while (true) {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        }

        boolean[] used = new boolean[n];
        int i = 0;
        int cnt = 0;
        while (true) {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = Integer.parseInt(scanner.nextLine()); n Integer.parseInt(scanner.nextLine()) Integer.parseInt Integer scanner.nextLine() scanner.nextLine scanner int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arr[i] = Integer.parseInt(scanner.nextLine());
        } {
            arr[i] = Integer.parseInt(scanner.nextLine());
        } arr[i] = Integer.parseInt(scanner.nextLine()) arr[i] arr i Integer.parseInt(scanner.nextLine()) Integer.parseInt Integer scanner.nextLine() scanner.nextLine scanner boolean[] used = new boolean[n]; used new boolean[n] n int i = 0; i 0 int cnt = 0; cnt 0 while (true) {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        } true {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        } cnt++ cnt if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            } arr[i] == 2 arr[i] arr i 2 {
                System.out.println(cnt);
                return;
            } System.out.println(cnt) System.out.println System.out System System.out cnt return; if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            } used[arr[i] - 1] used arr[i] - 1 arr[i] arr i 1 {
                System.out.println(-1);
                return;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 return; i = arr[i] - 1 i arr[i] - 1 arr[i] arr i 1 used[i] = true used[i] used i true String[] args args
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());

        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(scanner.nextLine());
        }

        boolean[] used = new boolean[n];
        int i = 0;
        int cnt = 0;
        while (true) {
            cnt++;
            if (arr[i] == 2) {
                System.out.println(cnt);
                return;
            }
            if (used[arr[i] - 1]) {
                System.out.println(-1);
                return;
            }
            i = arr[i] - 1;
            used[i] = true;
        }
    }
}
