
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int N;
    private static int[] a;
    private static int count = 0;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    }

    private static boolean check(int index) {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int N;
    private static int[] a;
    private static int count = 0;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    }

    private static boolean check(int index) {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    }
} Main private static Scanner scan = new Scanner(System.in); scan new Scanner(System.in) private static int N; N private static int[] a; a private static int count = 0; count 0 public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    } main {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    } N = Integer.parseInt(scan.next()) N Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan a = new int[N] a new int[N] N for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	} {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	} int index = Integer.parseInt(scan.next()) - 1; index Integer.parseInt(scan.next()) - 1 Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan 1 a[i] = index a[i] a i index System.out.println(check(0) ? count : -1) System.out.println System.out System System.out check(0) ? count : -1 check(0) check 0 count -1 1 scan.close() scan.close scan String[] args args private static boolean check(int index) {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    } check {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    } if(count >= N) return false; count >= N count N return false; false count++ count return a[index] == 1 ? true : check(a[index]); a[index] == 1 ? true : check(a[index]) a[index] == 1 a[index] a index 1 true check(a[index]) check a[index] a index int index index public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int N;
    private static int[] a;
    private static int count = 0;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    }

    private static boolean check(int index) {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    }
} public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int N;
    private static int[] a;
    private static int count = 0;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    }

    private static boolean check(int index) {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    }
} Main

import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int N;
    private static int[] a;
    private static int count = 0;

    public static void main(String[] args) {
	N = Integer.parseInt(scan.next());
	a = new int[N];

	for (int i = 0; i < N; i++) {
	    int index = Integer.parseInt(scan.next()) - 1;
	    a[i] = index;
	}

	System.out.println(check(0) ? count : -1);
	scan.close();
    }

    private static boolean check(int index) {
	if(count >= N) return false;

	count++;
	return a[index] == 1 ? true : check(a[index]);
    }
}
