import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}
 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.StringTokenizer; StringTokenizer java.util import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.InputStream; InputStream java.io public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
} Main public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(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;
        FastReader in = new FastReader(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 FastReader in = new FastReader(inputStream); in new FastReader(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, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        }

    } TaskB public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        } solve {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                arr[i] = in.nextInt() - 1;
            } {
                arr[i] = in.nextInt() - 1;
            } arr[i] = in.nextInt() - 1 arr[i] arr i in.nextInt() - 1 in.nextInt() in.nextInt in 1 boolean[] seen = new boolean[n]; seen new boolean[n] n int cur = 0; cur 0 int ans = 0; ans 0 while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            } true {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            } if (seen[cur]) {
                    out.println(-1);
                    return;
                } seen[cur] seen cur {
                    out.println(-1);
                    return;
                } out.println(-1) out.println out -1 1 return; if (cur == 1) {
                    out.println(ans);
                    return;
                } cur == 1 cur 1 {
                    out.println(ans);
                    return;
                } out.println(ans) out.println out ans return; seen[cur] = true seen[cur] seen cur true cur = arr[cur] cur arr[cur] arr cur ans += 1 ans 1 int testNumber testNumber FastReader in in PrintWriter out out static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    } FastReader BufferedReader reader; reader StringTokenizer st; st public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        } FastReader {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        } reader = new BufferedReader(new InputStreamReader(stream)) reader new BufferedReader(new InputStreamReader(stream)) st = null st null InputStream stream stream public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        } next {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        } while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            } st == null || !st.hasMoreTokens() st == null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            } try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                } catch (Exception e) {
                    throw new RuntimeException();
                } Exception e {
                    throw new RuntimeException();
                } throw new RuntimeException(); new RuntimeException() {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } String line = reader.readLine(); line reader.readLine() reader.readLine reader if (line == null) {
                        return null;
                    } line == null line null {
                        return null;
                    } return null; null st = new StringTokenizer(line) st new StringTokenizer(line) return st.nextToken(); st.nextToken() st.nextToken st public int nextInt() {
            return Integer.parseInt(next());
        } nextInt {
            return Integer.parseInt(next());
        } return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
} public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
} Main
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(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, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = in.nextInt() - 1;
            }
            boolean[] seen = new boolean[n];
            int cur = 0;
            int ans = 0;
            while (true) {
                if (seen[cur]) {
                    out.println(-1);
                    return;
                }
                if (cur == 1) {
                    out.println(ans);
                    return;
                }
                seen[cur] = true;
                cur = arr[cur];
                ans += 1;
            }
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

