import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    }
} Main public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    } main {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    } Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))); scan new Scanner(new BufferedReader(new InputStreamReader(System.in))) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] a = new int[N]; a new int[N] N boolean[] d = new boolean[N]; d new boolean[N] N for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            a[i] = scan.nextInt()-1;
        } {
            a[i] = scan.nextInt()-1;
        } a[i] = scan.nextInt()-1 a[i] a i scan.nextInt()-1 scan.nextInt() scan.nextInt scan 1 int current = 0; current 0 int answer = 0; answer 0 while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        } current != 1 && !d[current] current != 1 current 1 !d[current] d[current] d current {
            d[current] = true;
            current = a[current];
            answer += 1;
        } d[current] = true d[current] d current true current = a[current] current a[current] a current answer += 1 answer 1 if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        } current == 1 current 1 {
            System.out.println(answer);
        } System.out.println(answer) System.out.println System.out System System.out answer {
            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 scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int[] a = new int[N];
        boolean[] d = new boolean[N];
        for (int i = 0; i < N; i++) {
            a[i] = scan.nextInt()-1;
        }
        int current = 0;
        int answer = 0;
        while(current != 1 && !d[current]) {
            d[current] = true;
            current = a[current];
            answer += 1;
        }
        if (current == 1) {
            System.out.println(answer);
        } else {
            System.out.println(-1);
        }
    }
}
