import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		}
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		} catch (Exception e) {
			System.exit(0);
		} Exception e {
			System.exit(0);
		} System.exit(0) System.exit System 0 {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		} String str = br.readLine(); str br.readLine() br.readLine br int N = Integer.parseInt(str); N Integer.parseInt(str) Integer.parseInt Integer str int[] a = new int[N]; a new int[N] N for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			} {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			} str = br.readLine() str br.readLine() br.readLine br a[i] = Integer.parseInt(str) a[i] a i Integer.parseInt(str) Integer.parseInt Integer str int s = 1; s 1 int count = 0; count 0 while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			} true {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			} if(s == 2) {
					break;
				} s == 2 s 2 {
					break;
				} break; if(count == N) {
					count = -1;
					break;
				} count == N count N {
					count = -1;
					break;
				} count = -1 count -1 1 break; s = a[s-1] s a[s-1] a s-1 s 1 count++ count System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			int[] a = new int[N];
			for(int i = 0;i < N;i++) {
				str = br.readLine();
				a[i] = Integer.parseInt(str);
			}
			int s = 1;
			int count = 0;
			while(true) {
				if(s == 2) {
					break;
				}
				if(count == N) {
					count = -1;
					break;
				}
				s = a[s-1];
				count++;
			}
			System.out.println(count);
		}catch (Exception e) {
			System.exit(0);
		}
	}
}
