import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        int marker = 1,count=0;
        boolean tmp = false;
        for(int i = 0;i<n;i++){
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        }
        System.out.println(tmp?count:-1);
    }
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        int marker = 1,count=0;
        boolean tmp = false;
        for(int i = 0;i<n;i++){
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        }
        System.out.println(tmp?count:-1);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        int marker = 1,count=0;
        boolean tmp = false;
        for(int i = 0;i<n;i++){
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        }
        System.out.println(tmp?count:-1);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        int marker = 1,count=0;
        boolean tmp = false;
        for(int i = 0;i<n;i++){
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        }
        System.out.println(tmp?count:-1);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for(int i = 0;i<n;i++)a[i]=sc.nextInt(); int i = 0; int i = 0; i 0 i<n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int marker = 1 marker 1 count=0; count 0 boolean tmp = false; tmp false for(int i = 0;i<n;i++){
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        } {
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        } marker = a[marker-1] marker a[marker-1] a marker-1 marker 1 count++ count if(marker==2){
                tmp =true;
                break;
            } marker==2 marker 2 {
                tmp =true;
                break;
            } tmp =true tmp true break; System.out.println(tmp?count:-1) System.out.println System.out System System.out tmp?count:-1 tmp count -1 1 String[] args args
import java.util.*;
class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i = 0;i<n;i++)a[i]=sc.nextInt();
        int marker = 1,count=0;
        boolean tmp = false;
        for(int i = 0;i<n;i++){
            marker = a[marker-1];
            count++;
            if(marker==2){
                tmp =true;
                break;
            }
        }
        System.out.println(tmp?count:-1);
    }
}
