import java.util.Scanner;

public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        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 = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        System.out.println(-1);

    }
} Main public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        System.out.println(-1);

    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        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[] buttons = new int[n]; buttons new int[n] n for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1; int i = 0; int i = 0; i 0 i < buttons.length i buttons.length buttons buttons.length i++ i++ i buttons[i] = sc.nextInt() - 1; buttons[i] = sc.nextInt() - 1 buttons[i] buttons i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 int now = 0; now 0 int tmp; tmp for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        } {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        } tmp = buttons[now] tmp buttons[now] buttons now if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp; tmp == 1 tmp 1 {
                System.out.println(i+1);
                System.exit(0);
            } System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 System.exit(0) System.exit System 0 now = tmp now tmp 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 = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        System.out.println(-1);

    }
} public class Main {
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        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 = sc.nextInt();
        int[] buttons = new int[n];
        for(int i = 0; i < buttons.length;i++)
            buttons[i] = sc.nextInt() - 1;

        int now = 0;
        int tmp;
        for(int i = 0;i < n;i++)
        {
            tmp = buttons[now];
            if(tmp == 1) {
                System.out.println(i+1);
                System.exit(0);
            }
            else
                now = tmp;
        }
        System.out.println(-1);

    }
}
