import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	}
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	} main {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int x = s.nextInt(); x s.nextInt() s.nextInt s int i = 0; i 0 int ans = 0; ans 0 int ary[] = new int[x]; ary new int[x] x for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		} i = 0; i = 0 i 0 i < x i x i++ i++ i {
			ary[i] = s.nextInt();
		} {
			ary[i] = s.nextInt();
		} ary[i] = s.nextInt() ary[i] ary i s.nextInt() s.nextInt s Set<Integer> list = new HashSet<Integer>(); list new HashSet<Integer>() list.add(1) list.add list 1 for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		} i = 1; i = 1 i 1 {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		} {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		} i = ary[i - 1] i ary[i - 1] ary i - 1 i 1 int na=list.size(); na list.size() list.size list list.add(i) list.add list i ans++ ans if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			} i == 2 i 2 {
				break;
			} break; if (list.size()==na) {
				ans = -1;
				break;
			} list.size()==na list.size() list.size list na {
				ans = -1;
				break;
			} ans = -1 ans -1 1 break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	}
} public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	}
} Main
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int x = s.nextInt();
		int i = 0;
		int ans = 0;
		int ary[] = new int[x];
		for (i = 0; i < x; i++) {
			ary[i] = s.nextInt();
		}
		Set<Integer> list = new HashSet<Integer>();
		list.add(1);
		for (i = 1;;) {
			i = ary[i - 1];
			int na=list.size();
			list.add(i);
			ans++;
			if (i == 2) {
				break;
			} else if (list.size()==na) {
				ans = -1;
				break;
			}

		}
		System.out.println(ans);
	}
}