import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
} import java.util.*; util.* java public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
} Main void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    } solve {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1; int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = scan.nextInt() - 1; a[i] = scan.nextInt() - 1 a[i] a i scan.nextInt() - 1 scan.nextInt() scan.nextInt scan 1 int out = 0; out 0 for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        } int i = 0; int i = 0; i 0 out < n out n i = a[i] i = a[i] i a[i] a i {
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        } {
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        } if(i == 1){
                System.out.println(out);
                return;
            } i == 1 i 1 {
                System.out.println(out);
                return;
            } System.out.println(out) System.out.println System.out System System.out out return; out++ out System.out.println(-1) System.out.println System.out System System.out -1 1 scan.close() scan.close scan public static void main(String[] args){
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
} public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
} Main
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) a[i] = scan.nextInt() - 1;
        int out = 0;
        for(int i = 0; out < n; i = a[i]){
            if(i == 1){
                System.out.println(out);
                return;
            }
            out++;
        }
        System.out.println(-1);
        scan.close();
    }

    public static void main(String[] args){
        new Main().solve();
    }
}
