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

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.*; util.* java public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	}
} Main public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	} main {
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	} BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1); rd new BufferedReader(new InputStreamReader(System.in), 1) int n = Integer.parseInt(rd.readLine()); n Integer.parseInt(rd.readLine()) Integer.parseInt Integer rd.readLine() rd.readLine rd int a[] = new int[123456]; a new int[123456] 123456 for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			a[i] = Integer.parseInt(rd.readLine());
		} {
			a[i] = Integer.parseInt(rd.readLine());
		} a[i] = Integer.parseInt(rd.readLine()) a[i] a i Integer.parseInt(rd.readLine()) Integer.parseInt Integer rd.readLine() rd.readLine rd int c = 1; c 1 for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		} int i = 1; int i = 1; i 1 i <= 100001 i 100001 i++ i++ i {
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		} {
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		} c = a[c] c a[c] a c if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			} c == 2 c 2 {
				System.out.println(i);
				System.exit(0);
			} System.out.println(i) System.out.println System.out System System.out i System.exit(0) System.exit System 0 System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader rd = new BufferedReader(new InputStreamReader(System.in), 1);
	    int n = Integer.parseInt(rd.readLine());
	    //String[] sl = s.split(" ");
		int a[] = new int[123456];
		for(int i = 1; i <= n; i++)
		{
			a[i] = Integer.parseInt(rd.readLine());
		}
		
		int c = 1;
		for(int i = 1; i <= 100001; i++)
		{
			c = a[c];
			if(c == 2)
			{
				System.out.println(i);
				System.exit(0);
			}
		}
		System.out.println(-1);
		
  	}
}