import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aeroui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    }
}
 import java.io.OutputStream; OutputStream java.io import java.io.IOException; IOException java.io import java.io.InputStream; InputStream java.io import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    } main {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    } InputStream inputStream = System.in; inputStream System.in System System.in OutputStream outputStream = System.out; outputStream System.out System System.out Scanner in = new Scanner(inputStream); in new Scanner(inputStream) PrintWriter out = new PrintWriter(outputStream); out new PrintWriter(outputStream) TaskB solver = new TaskB(); solver new TaskB() solver.solve(1, in, out) solver.solve solver 1 in out out.close() out.close out String[] args args static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    } TaskB public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        } solve {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] arr = new int[n + 1]; arr new int[n + 1] n + 1 n 1 for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            } int i = 1; int i = 1; i 1 i <= n i n ++i ++i i {
                arr[i] = in.nextInt();
            } {
                arr[i] = in.nextInt();
            } arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in boolean[] vis = new boolean[n + 1]; vis new boolean[n + 1] n + 1 n 1 int cur = 1; cur 1 int ans = 0; ans 0 while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            } cur != 2 && !vis[cur] cur != 2 cur 2 !vis[cur] vis[cur] vis cur {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            } vis[cur] = true vis[cur] vis cur true cur = arr[cur] cur arr[cur] arr cur ++ans ans out.println(cur != 2 ? -1 : ans) out.println out cur != 2 ? -1 : ans cur != 2 cur 2 -1 1 ans int testNumber testNumber Scanner in in PrintWriter out out public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Aeroui
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n + 1];
            for (int i = 1; i <= n; ++i) {
                arr[i] = in.nextInt();
            }

            boolean[] vis = new boolean[n + 1];
            int cur = 1;
            int ans = 0;
            while (cur != 2 && !vis[cur]) {
                vis[cur] = true;
                cur = arr[cur];
                ++ans;
            }

            out.println(cur != 2 ? -1 : ans);

        }

    }
}

