
import java.util.*;
import java.util.stream.IntStream;

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

        }

        int currentIndex = 0;
        int goalIndex = 1;
        int tryCount = n;

        while (currentIndex != goalIndex && tryCount > 0){
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        }

        if(currentIndex == goalIndex){
            System.out.print(n- tryCount);
            return;
        }

        System.out.print(-1);
    }
} import java.util.*; util.* java import java.util.stream.IntStream; IntStream 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();

        }

        int currentIndex = 0;
        int goalIndex = 1;
        int tryCount = n;

        while (currentIndex != goalIndex && tryCount > 0){
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        }

        if(currentIndex == goalIndex){
            System.out.print(n- tryCount);
            return;
        }

        System.out.print(-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();

        }

        int currentIndex = 0;
        int goalIndex = 1;
        int tryCount = n;

        while (currentIndex != goalIndex && tryCount > 0){
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        }

        if(currentIndex == goalIndex){
            System.out.print(n- tryCount);
            return;
        }

        System.out.print(-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 currentIndex = 0;
        int goalIndex = 1;
        int tryCount = n;

        while (currentIndex != goalIndex && tryCount > 0){
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        }

        if(currentIndex == goalIndex){
            System.out.print(n- tryCount);
            return;
        }

        System.out.print(-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 int currentIndex = 0; currentIndex 0 int goalIndex = 1; goalIndex 1 int tryCount = n; tryCount n while (currentIndex != goalIndex && tryCount > 0){
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        } currentIndex != goalIndex && tryCount > 0 currentIndex != goalIndex currentIndex goalIndex tryCount > 0 tryCount 0 {
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        } int index = a[currentIndex]; index a[currentIndex] a currentIndex currentIndex = index-1 currentIndex index-1 index 1 --tryCount tryCount if(currentIndex == goalIndex){
            System.out.print(n- tryCount);
            return;
        } currentIndex == goalIndex currentIndex goalIndex {
            System.out.print(n- tryCount);
            return;
        } System.out.print(n- tryCount) System.out.print System.out System System.out n- tryCount n tryCount return; System.out.print(-1) System.out.print System.out System System.out -1 1 String[] args args

import java.util.*;
import java.util.stream.IntStream;

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

        }

        int currentIndex = 0;
        int goalIndex = 1;
        int tryCount = n;

        while (currentIndex != goalIndex && tryCount > 0){
            int index = a[currentIndex];
            currentIndex = index-1;
            --tryCount;
        }

        if(currentIndex == goalIndex){
            System.out.print(n- tryCount);
            return;
        }

        System.out.print(-1);
    }
}