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[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    }
} 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[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    }
} Main public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n int on = 0; on 0 for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int m = 0; m 0 int count = 0; count 0 for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        } {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        } m = array[m] - 1 m array[m] - 1 array[m] array m 1 count++ count if (m == 1) {
                break;
            } m == 1 m 1 {
                break;
            } break; if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        } count == n count n {
            System.out.println(-1);
        } System.out.println(-1) System.out.println System.out System System.out -1 1 {
            System.out.println(count);
        } System.out.println(count) System.out.println System.out System System.out count 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[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    }
} public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    }
} 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[] array = new int[n];
        int on = 0;
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        int m = 0;
        int count = 0;
        for (int i = 0; i < n; i++) {
            m = array[m] - 1;
            count++;
            if (m == 1) {
                break;
            }
        }
        if (count == n) {
            System.out.println(-1);
        } else {
            System.out.println(count);
        }
    }
}
