import java.util.*;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;

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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(count);
		
	}
} import java.util.*; util.* java import java.math.BigInteger; BigInteger java.math import java.security.NoSuchAlgorithmException; NoSuchAlgorithmException java.security import java.util.ArrayList; ArrayList java.util import java.util.HashMap; HashMap 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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(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()-1;
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			a[i] = sc.nextInt()-1;
		} {
			a[i] = sc.nextInt()-1;
		} a[i] = sc.nextInt()-1 a[i] a i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 boolean[] use = new boolean[N]; use new boolean[N] N int id = 0; id 0 int count = 0; count 0 while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		} true {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		} if(use[id]) {
				count = -1;
				break;
			} use[id] use id {
				count = -1;
				break;
			} count = -1 count -1 1 break; if(id == 1) {
				break;
			} id == 1 id 1 {
				break;
			} break; use[id] = true use[id] use id true count++ count id = a[id] id a[id] a id System.out.println(count) System.out.println System.out System System.out 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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(count);
		
	}
} Main
import java.util.*;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.HashMap;

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()-1;
		}
		
		boolean[] use = new boolean[N];
		int id = 0;
		int count = 0;
		while(true) {
			if(use[id]) {
				count = -1;
				break;
			}
			if(id == 1) {
				break;
			}
			use[id] = true;
			count++;
			id = a[id];
		}
		System.out.println(count);
		
	}
}