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 Echizen
 */
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;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    }
}
 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;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    }
} 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;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    } TaskB public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        } solve {
            int n;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        } int n; n n = in.nextInt() n in.nextInt() in.nextInt in int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            } int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length 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 flag = false; flag false int i = 1 i 1 j = 0; j 0 while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            } j++ < n j++ j n {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            } if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                } arr[i - 1] == 2 arr[i - 1] arr i - 1 i 1 2 {
                    flag = true;
                    break;
                } flag = true flag true break; {
                    i = arr[i - 1];
                } i = arr[i - 1] i arr[i - 1] arr i - 1 i 1 out.println(flag == true ? j : -1) out.println out flag == true ? j : -1 flag == true flag true j -1 1 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;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    }
} 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;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    }
} 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 Echizen
 */
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;
            n = in.nextInt();
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++) {
                arr[i] = in.nextInt();
            }
            boolean flag = false;
            int i = 1, j = 0;
            while (j++ < n) {
                if (arr[i - 1] == 2) {
                    flag = true;
                    break;
                } else {
                    i = arr[i - 1];
                }
            }
            out.println(flag == true ? j : -1);
        }

    }
}

