import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	}
} Main public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	} main {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[]A = new int[N]; A new int[N] N for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		} int a=0; int a=0; a 0 a<N a N a++ a++ a {
			A[a] = Integer.parseInt(br.readLine());
		} {
			A[a] = Integer.parseInt(br.readLine());
		} A[a] = Integer.parseInt(br.readLine()) A[a] A a Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int count = 0; count 0 int now = 1; now 1 for(;count<N && now!=2;count++,now = A[now-1]) {
		} ; count<N && now!=2 count<N count N now!=2 now 2 count++,now = A[now-1] count++ count now = A[now-1] now A[now-1] A now-1 now 1 {
		} {
		} if(count == N)count = -1; count == N count N count = -1 count -1 1 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) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	}
} Main
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int N = Integer.parseInt(br.readLine());
		int[]A = new int[N];
		for(int a=0;a<N;a++) {
			A[a] = Integer.parseInt(br.readLine());
		}
		
		int count = 0;
		int now = 1;
		for(;count<N && now!=2;count++,now = A[now-1]) {
		}
		if(count == N)count = -1;
		
		System.out.println(count);	
	}
}