import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
} Main BufferedReader br; br StringTokenizer st; st PrintWriter out; out private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	} solve {
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	} int n=nextInt(); n nextInt() nextInt int a[]=new int[n+1]; a new int[n+1] n+1 n 1 for(int i=1;i<=n;i++)
			a[i]=nextInt(); int i=1; int i=1; i 1 i<=n i n i++ i++ i a[i]=nextInt(); a[i]=nextInt() a[i] a i nextInt() nextInt int curr=1; curr 1 int moves=0; moves 0 boolean visited[]=new boolean[n+1]; visited new boolean[n+1] n+1 n 1 while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		} curr!=2 curr 2 {
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		} if(visited[curr])
			{
				out.println(-1);
				return;
			} visited[curr] visited curr {
				out.println(-1);
				return;
			} out.println(-1) out.println out -1 1 return; visited[curr]=true visited[curr] visited curr true curr=a[curr] curr a[curr] a curr moves++ moves out.println(moves) out.println out moves public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	} run {
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	} br=new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) st=null st null out=new PrintWriter(System.out) out new PrintWriter(System.out) solve() solve br.close() br.close br out.close() out.close out public static void main(String args[])throws IOException{
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String args[] args String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	} nextToken {
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	} while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine()); st==null || !st.hasMoreTokens() st==null st null !st.hasMoreTokens() st.hasMoreTokens() st.hasMoreTokens st st=new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st String nextLine()throws IOException{
		return br.readLine();
	} nextLine {
		return br.readLine();
	} return br.readLine(); br.readLine() br.readLine br int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	} nextInt {
		return Integer.parseInt(nextToken());
	} return Integer.parseInt(nextToken()); Integer.parseInt(nextToken()) Integer.parseInt Integer nextToken() nextToken long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	} nextLong {
		return Long.parseLong(nextToken());
	} return Long.parseLong(nextToken()); Long.parseLong(nextToken()) Long.parseLong Long nextToken() nextToken double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	} nextDouble {
		return Double.parseDouble(nextToken());
	} return Double.parseDouble(nextToken()); Double.parseDouble(nextToken()) Double.parseDouble Double nextToken() nextToken public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
} public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
} Main
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		int n=nextInt();
		int a[]=new int[n+1];
		for(int i=1;i<=n;i++)
			a[i]=nextInt();
		int curr=1;
		int moves=0;
		boolean visited[]=new boolean[n+1];
		while(curr!=2)
		{
			if(visited[curr])
			{
				out.println(-1);
				return;
			}
			visited[curr]=true;
			curr=a[curr];
			moves++;
		}
		out.println(moves);
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();
		
		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}