// package app;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    }
} import java.math.BigDecimal; BigDecimal java.math import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.HashMap; HashMap java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Objects; Objects java.util import java.util.Scanner; Scanner java.util import java.util.StringJoiner; StringJoiner java.util import java.util.stream.Stream; Stream java.util.stream public class Main {

    public static void main(final String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    }
} Main public static void main(final String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc List<Integer> a = new ArrayList<Integer>(); a new ArrayList<Integer>() for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        } {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        } a.add(sc.nextInt() - 1) a.add a sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 boolean[] isTrace = new boolean[N]; isTrace new boolean[N] N int currPos = 0; currPos 0 int cnt = 0; cnt 0 while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        } !isTrace[currPos] isTrace[currPos] isTrace currPos {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        } if (currPos == 1) break; currPos == 1 currPos 1 break; isTrace[currPos] = true isTrace[currPos] isTrace currPos true currPos = a.get(currPos) currPos a.get(currPos) a.get a currPos cnt++ cnt System.out.println(currPos == 1 ? cnt : -1) System.out.println System.out System System.out currPos == 1 ? cnt : -1 currPos == 1 currPos 1 cnt -1 1 final String[] args args public class Main {

    public static void main(final String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    }
} public class Main {

    public static void main(final String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    }
} Main
// package app;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.StringJoiner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        // int K = sc.nextInt();

        // int[] a = new int[N];
        List<Integer> a = new ArrayList<Integer>();
        for (int i = 0; i < N; i++) {
            // a[i] = sc.nextInt();
            // a.add(i);
            a.add(sc.nextInt() - 1);
        }

        boolean[] isTrace = new boolean[N];

        int currPos = 0;
        int cnt = 0;
        while(!isTrace[currPos]) {
            if (currPos == 1) break;
            isTrace[currPos] = true;
            currPos = a.get(currPos);
            cnt++;
        }

        System.out.println(currPos == 1 ? cnt : -1);

    }
}