import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    }

} 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[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    }

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        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[] an = new int[n+1]; an new int[n+1] n+1 n 1 for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            an[i] = sc.nextInt();
        } {
            an[i] = sc.nextInt();
        } an[i] = sc.nextInt() an[i] an i sc.nextInt() sc.nextInt sc int j = an[1]; j an[1] an 1 for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        } int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        } {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        } if (j == 2) {
                System.out.println(i);
                System.exit(0);
            } j == 2 j 2 {
                System.out.println(i);
                System.exit(0);
            } System.out.println(i) System.out.println System.out System System.out i System.exit(0) System.exit System 0 j = an[j] j an[j] an j 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 sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    }

} public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] an = new int[n+1];
        for (int i = 1; i <= n; i++) {
            an[i] = sc.nextInt();
        }

        int j = an[1];
        for (int i = 1; i <= n; i++) {
            if (j == 2) {
                System.out.println(i);
                System.exit(0);
            }
            j = an[j];
        }
        System.out.println(-1);
    }

}