import java.util.*;

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();
        }
        int pivot = A[0];
        if (pivot == 2) {
            System.out.println(1);
            return;
        }
        for (int i = 1; i < N; i++) {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        }
        System.out.println(-1);
    }
} import java.util.*; util.* java 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();
        }
        int pivot = A[0];
        if (pivot == 2) {
            System.out.println(1);
            return;
        }
        for (int i = 1; i < N; i++) {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        }
        System.out.println(-1);
    }
} 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();
        }
        int pivot = A[0];
        if (pivot == 2) {
            System.out.println(1);
            return;
        }
        for (int i = 1; i < N; i++) {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        }
        System.out.println(-1);
    } 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();
        }
        int pivot = A[0];
        if (pivot == 2) {
            System.out.println(1);
            return;
        }
        for (int i = 1; i < N; i++) {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        }
        System.out.println(-1);
    } 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();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int pivot = A[0]; pivot A[0] A 0 if (pivot == 2) {
            System.out.println(1);
            return;
        } pivot == 2 pivot 2 {
            System.out.println(1);
            return;
        } System.out.println(1) System.out.println System.out System System.out 1 return; for (int i = 1; i < N; i++) {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        } int i = 1; int i = 1; i 1 i < N i N i++ i++ i {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        } {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        } pivot = A[pivot - 1] pivot A[pivot - 1] A pivot - 1 pivot 1 if (pivot == 2) {
                System.out.println(i + 1);
                return;
            } pivot == 2 pivot 2 {
                System.out.println(i + 1);
                return;
            } System.out.println(i + 1) System.out.println System.out System System.out i + 1 i 1 return; System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args
import java.util.*;

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();
        }
        int pivot = A[0];
        if (pivot == 2) {
            System.out.println(1);
            return;
        }
        for (int i = 1; i < N; i++) {
            pivot = A[pivot - 1];
            if (pivot == 2) {
                System.out.println(i + 1);
                return;
            }
        }
        System.out.println(-1);
    }
}