import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) throws Exception {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
} Main public static void main(String[] args) throws Exception {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    } main {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    } try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        } catch (Exception e) {
            System.out.println(e);
        } Exception e {
            System.out.println(e);
        } System.out.println(e) System.out.println System.out System System.out e {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                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[] input = new int[n]; input new int[n] n for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                input[i] = sc.nextInt();
            } {
                input[i] = sc.nextInt();
            } input[i] = sc.nextInt() input[i] input i sc.nextInt() sc.nextInt sc int now = input[0]; now input[0] input 0 int count = 1; count 1 boolean flag = false; flag false while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            } count < n count n {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            } if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                } now == 2 now 2 {
                    System.out.println(count);
                    flag = true;
                    break;
                } System.out.println(count) System.out.println System.out System System.out count flag = true flag true break; now = input[now - 1] now input[now - 1] input now - 1 now 1 count++ count if (!flag) {
                System.out.println(-1);
            } !flag flag {
                System.out.println(-1);
            } 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) throws Exception {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int[] input = new int[n];
            for (int i = 0; i < n; i++) {
                input[i] = sc.nextInt();
            }

            int now = input[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = input[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
