import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.HashSet; HashSet java.util import java.util.List; List java.util import java.util.Set; Set java.util class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
} Main public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    } main {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    } try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } IOException | NumberFormatException e {
            e.printStackTrace();
            System.exit(0);
        } e.printStackTrace() e.printStackTrace e System.exit(0) System.exit System 0 catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        } final Exception e {
            e.printStackTrace();
            System.exit(0);
        } e.printStackTrace() e.printStackTrace e System.exit(0) System.exit System 0 {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br List<Integer> numbers = new ArrayList<>(); numbers new ArrayList<>() for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            } {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            } numbers.add(Integer.parseInt(br.readLine()) - 1) numbers.add numbers Integer.parseInt(br.readLine()) - 1 Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br 1 int now = 0; now 0 int ans = 0; ans 0 for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            } int i = 0; int i = 0; i 0 i < numbers.size() + 1 i numbers.size() + 1 numbers.size() numbers.size numbers 1 i++ i++ i {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            } {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            } if (now == 1) {
                    System.out.println(ans);
                    break;
                } now == 1 now 1 {
                    System.out.println(ans);
                    break;
                } System.out.println(ans) System.out.println System.out System System.out ans break; if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                } ans >= N ans N {
                    ans = -1;
                    System.out.println(ans);
                    break;
                } ans = -1 ans -1 1 System.out.println(ans) System.out.println System.out System System.out ans break; ans++ ans now = numbers.get(now) now numbers.get(now) numbers.get numbers now final String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());
            List<Integer> numbers = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                numbers.add(Integer.parseInt(br.readLine()) - 1);
            }

            int now = 0;
            int ans = 0;
            for (int i = 0; i < numbers.size() + 1; i++) {
                if (now == 1) {
                    System.out.println(ans);
                    break;
                }

                if (ans >= N) {
                    ans = -1;
                    System.out.println(ans);
                    break;
                }

                ans++;
                now = numbers.get(now);
            }

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}