import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] al = new int[n]; al new int[n] n for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            al[i] = sc.nextInt()-1;
        } {
            al[i] = sc.nextInt()-1;
        } al[i] = sc.nextInt()-1 al[i] al i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int ans = 0; ans 0 int ind = 0; ind 0 HashSet<Integer> hs = new HashSet<Integer>(); hs new HashSet<Integer>() while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        } true {
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        } if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            } hs.contains(ind) hs.contains hs ind {
                System.out.println(-1);
                break;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 break; if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            } ind == 1 ind 1 {
                System.out.println(ans);
                break;
            } System.out.println(ans) System.out.println System.out System System.out ans break; {
                ans++;
                hs.add(ind);
                ind = al[ind];
            } ans++ ans hs.add(ind) hs.add hs ind ind = al[ind] ind al[ind] al ind String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] al = new int[n];
        for(int i = 0; i < n; i++){
            al[i] = sc.nextInt()-1;
        }
        int ans = 0;
        int ind = 0;
        HashSet<Integer> hs = new HashSet<Integer>();
        while(true){
            if(hs.contains(ind)){
                System.out.println(-1);
                break;
            }else if(ind == 1){
                System.out.println(ans);
                break;
            }else{
                ans++;
                hs.add(ind);
                ind = al[ind];
            }
        }
    }
}