import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] a = new int[n]; a new int[n] n boolean[] isA = new boolean[n]; isA new boolean[n] n for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = scanner.nextInt();
        } {
            a[i] = scanner.nextInt();
        } a[i] = scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner int count = 0; count 0 int i = 0; i 0 while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        } i != 1 && !isA[i] i != 1 i 1 !isA[i] isA[i] isA i {
            isA[i] = true;
            i = a[i]-1;
            count++;
        } isA[i] = true isA[i] isA i true i = a[i]-1 i a[i]-1 a[i] a i 1 count++ count if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        } i == 1 i 1 {
            System.out.println(count);
        } System.out.println(count) System.out.println System.out System System.out count {
            System.out.println(-1);
        } System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        boolean[] isA = new boolean[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int count = 0;
        int i = 0;
        while(i != 1 && !isA[i]){
            isA[i] = true;
            i = a[i]-1;
            count++;
        }
        if (i == 1){
            System.out.println(count);
        }else {
            System.out.println(-1);
        }
    }
}
