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[] a = new int[N];
        for(int i = 0; i < N; i++) a[i] = sc.nextInt();

        int button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? count : -1);
    }
}
  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[] a = new int[N];
        for(int i = 0; i < N; i++) a[i] = sc.nextInt();

        int button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? count : -1);
    }
} Main public static void main(String[] args) throws Exception {

        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 button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? 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 button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? 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 button = 0; button 0 int count = 1; count 1 while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        } a[button] != 2 a[button] a button 2 {
            button = a[button] - 1;
            count++;
            if(count > N) break;
        } button = a[button] - 1 button a[button] - 1 a[button] a button 1 count++ count if(count > N) break; count > N count N break; System.out.println( count < N ? count : -1) System.out.println System.out System System.out count < N ? count : -1 count < N count N count -1 1 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[] a = new int[N];
        for(int i = 0; i < N; i++) a[i] = sc.nextInt();

        int button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? count : -1);
    }
} public class Main {
    public static void main(String[] args) throws Exception {

        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 button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? count : -1);
    }
} 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[] a = new int[N];
        for(int i = 0; i < N; i++) a[i] = sc.nextInt();

        int button = 0;
        int count = 1;
        while(a[button] != 2){
            button = a[button] - 1;
            count++;
            if(count > N) break;
        }
        System.out.println( count < N ? count : -1);
    }
}
 