import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    } 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 int flag = 0; flag 0 int cash = 1; cash 1 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] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        } int i = 0; int i = 0; i 0 i++ i++ i {
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        } {
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        } cash = a[cash - 1] cash a[cash - 1] a cash - 1 cash 1 flag++ flag if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            } cash == 2 cash 2 {
                break;
            } break; if(flag > N){
                flag = -1;
                break;
            } flag > N flag N {
                flag = -1;
                break;
            } flag = -1 flag -1 1 break; System.out.println(flag) System.out.println System.out System System.out flag String[] args args public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        int flag = 0;
        int cash = 1;
        for(int i = 0 ; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0;;i++){
            cash = a[cash - 1];
            flag++;
            if(cash == 2){
                break;
            }else if(flag > N){
                flag = -1;
                break;
            }
        }
        System.out.println(flag);
    }
}