import javax.swing.*;
import java.util.*;



/**
 * Created by santa on 2016/10/16.
 */

public class Main {


    static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        }

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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



    }




} // MainClass import javax.swing.*; swing.* javax import java.util.*; util.* java public class Main {


    static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        }

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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



    }




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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = scanner.nextInt() - 1;
        } {
            a[i] = scanner.nextInt() - 1;
        } a[i] = scanner.nextInt() - 1 a[i] a i scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 int[] list = new int[N]; list new int[N] N int next = 0; next 0 int c = 1; c 1 int flag = 0; flag 0 while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        } true {
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        } if(a[next] == 1){
                flag = c;
                break;
            } a[next] == 1 a[next] a next 1 {
                flag = c;
                break;
            } flag = c flag c break; next = a[next] next a[next] a next if(list[next] == 1){
                flag = -1;
                break;
            } list[next] == 1 list[next] list next 1 {
                flag = -1;
                break;
            } flag = -1 flag -1 1 break; list[next] = 1 list[next] list next 1 c++ c System.out.println(flag) System.out.println System.out System System.out flag String[] args args static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        } pair public int a; a public int b; b pair(){
                this.a = 0;
                this.b = 0;
            } pair {
                this.a = 0;
                this.b = 0;
            } this.a = 0 this.a this this.a 0 this.b = 0 this.b this this.b 0 pair(int a, int b){
                this.a = a;
                this.b = b;
            } pair {
                this.a = a;
                this.b = b;
            } this.a = a this.a this this.a a this.b = b this.b this this.b b int a a int b b public void set(int a, int b) {
                this.a = a;
                this.b = b;
            } set {
                this.a = a;
                this.b = b;
            } this.a = a this.a this this.a a this.b = b this.b this this.b b int a a int b b public class Main {


    static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        }

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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



    }




} // MainClass public class Main {


    static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        }

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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



    }




} // MainClass Main
import javax.swing.*;
import java.util.*;



/**
 * Created by santa on 2016/10/16.
 */

public class Main {


    static class pair {
            public int a;
            public int b;

            pair(){
                this.a = 0;
                this.b = 0;
            }

            pair(int a, int b){
                this.a = a;
                this.b = b;
            }

            public void set(int a, int b) {
                this.a = a;
                this.b = b;
            }
        }

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

        int N = scanner.nextInt();


        int[] a = new int[N];

        for (int i = 0; i < N; i++) {
            a[i] = scanner.nextInt() - 1;
        }

        int[] list = new int[N];
        int next = 0;
        int c = 1;
        int flag = 0;
        while(true){
            if(a[next] == 1){
                flag = c;
                break;
            }
            next = a[next];
            if(list[next] == 1){
                flag = -1;
                break;
            }
            list[next] = 1;
            c++;
        }

        System.out.println(flag);



    }




} // MainClass
