import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        } {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        } int temp = Integer.parseInt(sc.next()); temp Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc a[i] = temp - 1 a[i] a i temp - 1 temp 1 int idx = 0; idx 0 int cnt = 0; cnt 0 for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        } {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        } cnt++ cnt idx = a[idx] idx a[idx] a idx if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            } idx == 1 idx 1 {
                System.out.println(cnt);
                return;
            } System.out.println(cnt) System.out.println System.out System System.out cnt return; if (idx == 0) {
                System.out.println(-1);
                return;
            } idx == 0 idx 0 {
                System.out.println(-1);
                return;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 return; System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp - 1;
        }
        int idx = 0;
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt++;
            idx = a[idx];
            if (idx == 1) {
                System.out.println(cnt);
                return;
            } else if (idx == 0) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(-1);
    }
}