import java.util.Arrays;
import java.util.Scanner;

public 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    }
} import java.util.Arrays; Arrays java.util import java.util.Scanner; Scanner java.util public 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    }
} 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    } 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    } 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 next = 0; next 0 int count = 0; count 0 int past[] = new int[100000]; past new int[100000] 100000 Arrays.fill(past, 0) Arrays.fill Arrays past 0 while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        } true {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        } if (next == 1) {
                System.out.println(count);
                return;
            } next == 1 next 1 {
                System.out.println(count);
                return;
            } System.out.println(count) System.out.println System.out System System.out count return; if (past[next] == 1) {
                System.out.println(-1);
                return;
            } past[next] == 1 past[next] past next 1 {
                System.out.println(-1);
                return;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 return; past[next] = 1 past[next] past next 1 next = a[next] - 1 next a[next] - 1 a[next] a next 1 count++ count String[] args args public 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    }
} public 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    }
} Main
import java.util.Arrays;
import java.util.Scanner;

public 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 next = 0;
        int count = 0;
        int past[] = new int[100000]; 
        Arrays.fill(past, 0);
        while (true) {
            if (next == 1) {
                System.out.println(count);
                return;
            }

            if (past[next] == 1) {
                System.out.println(-1);
                return;
            }

            past[next] = 1;
            next = a[next] - 1;
            count++;
        }
    }
}
