import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

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();

        }
        boolean isFinish = false;
        int initial = 1;
        int result = 0;
        for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        }

        if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-1);

        }
    }
} import java.math.BigDecimal; BigDecimal java.math import java.util.*; util.* java import java.util.stream.Collectors; Collectors java.util.stream 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();

        }
        boolean isFinish = false;
        int initial = 1;
        int result = 0;
        for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        }

        if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-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();

        }
        boolean isFinish = false;
        int initial = 1;
        int result = 0;
        for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        }

        if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-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();

        }
        boolean isFinish = false;
        int initial = 1;
        int result = 0;
        for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        }

        if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-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] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc boolean isFinish = false; isFinish false int initial = 1; initial 1 int result = 0; result 0 for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        } {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        } initial = a[initial - 1] initial a[initial - 1] a initial - 1 initial 1 result++ result if (initial == 2) {
                isFinish = true;
                break;
            } initial == 2 initial 2 {
                isFinish = true;
                break;
            } isFinish = true isFinish true break; if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-1);

        } isFinish {
            System.out.println(result);
        } System.out.println(result) System.out.println System.out System System.out result {
            System.out.println(-1);

        } System.out.println(-1) System.out.println System.out System System.out -1 1 String args[] args
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

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();

        }
        boolean isFinish = false;
        int initial = 1;
        int result = 0;
        for (int i = 0; i < n; i++) {
            initial = a[initial - 1];
            result++;
            if (initial == 2) {
                isFinish = true;
                break;
            }
        }

        if (isFinish) {
            System.out.println(result);
        } else {
            System.out.println(-1);

        }
    }
}