import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	}

} import java.util.ArrayList; ArrayList 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 = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = Integer.parseInt(sc.next()); N Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc ArrayList<Integer> botton = new ArrayList<>(); botton new ArrayList<>() for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			botton.add(Integer.parseInt(sc.next()) - 1);
		} {
			botton.add(Integer.parseInt(sc.next()) - 1);
		} botton.add(Integer.parseInt(sc.next()) - 1) botton.add botton Integer.parseInt(sc.next()) - 1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 1 sc.close() sc.close sc int count = 0; count 0 int now = 0; now 0 for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		} int i = 0; int i = 0; i 0 i <= N i N i++ i++ i {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		} {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		} if(now == 1) {
				System.out.println(count);
				return;
			} now == 1 now 1 {
				System.out.println(count);
				return;
			} System.out.println(count) System.out.println System.out System System.out count return; if(count == N) {
				System.out.println(-1);
				return;
			} count == N count N {
				System.out.println(-1);
				return;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 return; count++ count now = botton.get(now) now botton.get(now) botton.get botton now String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	}

} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> botton = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			botton.add(Integer.parseInt(sc.next()) - 1);
		}
		sc.close();

		int count = 0;
		int now = 0;

		for(int i = 0; i <= N ;i++) {
			if(now == 1) {
				System.out.println(count);
				return;
			}
			if(count == N) {
				System.out.println(-1);
				return;
			}
			count++;
			now = botton.get(now);
		}
	}

}