import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	}
	
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	}
	
} Main public static void main(String[] args){
		new Main().solve();
	} main {
		new Main().solve();
	} new Main().solve() new Main().solve new Main() String[] args args void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	} solve {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	} 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+1]; a new int[N+1] N+1 N 1 for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			a[i+1]=sc.nextInt();
		} {
			a[i+1]=sc.nextInt();
		} a[i+1]=sc.nextInt() a[i+1] a i+1 i 1 sc.nextInt() sc.nextInt sc int count=0; count 0 int now=1; now 1 while(count<N && now!=2){
			now=a[now];
			count++;
		} count<N && now!=2 count<N count N now!=2 now 2 {
			now=a[now];
			count++;
		} now=a[now] now a[now] a now count++ count if(now==2)System.out.println(count);
		else System.out.println(-1); now==2 now 2 System.out.println(count) System.out.println System.out System System.out count System.out.println(-1) System.out.println System.out System System.out -1 1 public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	}
	
} public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	}
	
} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[]a=new int[N+1];
		for(int i=0;i<N;i++){
			a[i+1]=sc.nextInt();
		}
		
		int count=0;
		int now=1;
		while(count<N && now!=2){
			now=a[now];
			count++;
		}
		
		if(now==2)System.out.println(count);
		else System.out.println(-1);
	}
	
}