import java.util.Scanner;

// Java8
public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	
} import java.util.Scanner; Scanner java.util public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) throws Exception
	{
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	} run {
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] as = new int[n+1]; as new int[n+1] n+1 n 1 for(int i=1; i<=n; i++) as[i] = sc.nextInt(); int i=1; int i=1; i 1 i<=n i n i++ i++ i as[i] = sc.nextInt(); as[i] = sc.nextInt() as[i] as i sc.nextInt() sc.nextInt sc int p = 1; p 1 for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		} {
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		} p = as[p] p as[p] as p if(p==2)
			{
				System.out.println(i);
				return;
			} p==2 p 2 {
				System.out.println(i);
				return;
			} System.out.println(i) System.out.println System.out System System.out i return; System.out.println(-1) System.out.println System.out System System.out -1 1 public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	
} public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	
} Main
import java.util.Scanner;

// Java8
public class Main
{
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) throws Exception
	{
		new Main().run();
	}
	
	void run()
	{
		int n = sc.nextInt();
		int[] as = new int[n+1];
		for(int i=1; i<=n; i++) as[i] = sc.nextInt();
		int p = 1;
		for(int i=1; i<=n; i++)
		{
			p = as[p];
			if(p==2)
			{
				System.out.println(i);
				return;
			}
		}
		System.out.println(-1);
	}
	
}
