import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	}
} import java.io.File; File java.io import java.io.IOException; IOException java.io import java.util.*; util.* java import java.util.Map.Entry; Entry java.util.Map public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	}
} Main public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	} main {
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int N = in.nextInt(); N in.nextInt() in.nextInt in HashMap<Integer, Integer> map = new HashMap<Integer, Integer>(); map new HashMap<Integer, Integer>() for(int i = 0; i < N; i++) map.put(i+1, in.nextInt()); int i = 0; int i = 0; i 0 i < N i N i++ i++ i map.put(i+1, in.nextInt()); map.put(i+1, in.nextInt()) map.put map i+1 i 1 in.nextInt() in.nextInt in int button = 1; button 1 int count = 0; count 0 for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		} {
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		} button = map.get(button) button map.get(button) map.get map button count++ count if(button == 2){
				System.out.println(count);
				return;
			} button == 2 button 2 {
				System.out.println(count);
				return;
			} System.out.println(count) System.out.println System.out System System.out count return; 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 IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	}
} public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	}
} Main
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;

public class Main{
	
	public static void main(String[] args) throws IOException{
		//File file = new File("input.txt");
		//Scanner in = new Scanner(file);
		Scanner in = new Scanner(System.in);
		
		int N = in.nextInt();
		HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
		for(int i = 0; i < N; i++) map.put(i+1, in.nextInt());
		
		int button = 1;
		int count = 0;
		for(int i = 0; i < N; i++){
			button = map.get(button);
			count++;
			if(button == 2){
				System.out.println(count);
				return;
			}
		}
		
		System.out.println(-1);
	}
}
