import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    }
    
} import java.util.*; util.* java public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    }
    
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    } main {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] map = new int[N]; map new int[N] N for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
        	map[i] = sc.nextInt();
        } {
        	map[i] = sc.nextInt();
        } map[i] = sc.nextInt() map[i] map i sc.nextInt() sc.nextInt sc int count = 0; count 0 int index = 1; index 1 while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        } true {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        } if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	} map[index-1] == 2 map[index-1] map index-1 index 1 2 {
        		count++;
        		System.out.println(count);
        		return;
        	} count++ count System.out.println(count) System.out.println System.out System System.out count return; {
        		count++;
        		index = map[index-1];
        	} count++ count index = map[index-1] index map[index-1] map index-1 index 1 if (count > N) {
        		System.out.println(-1);
        		return;
        	} count > N count N {
        		System.out.println(-1);
        		return;
        	} System.out.println(-1) System.out.println System.out System System.out -1 1 return; String[] args args public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    }
    
} public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    }
    
} Main
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[N];
        for (int i = 0; i < N; i++) {
        	map[i] = sc.nextInt();
        }
        
        int count = 0;
        int index = 1;
        while(true) {
        	if (map[index-1] == 2) {
        		count++;
        		System.out.println(count);
        		return;
        	} else {
        		count++;
        		index = map[index-1];
        	}
        	
        	if (count > N) {
        		System.out.println(-1);
        		return;
        	}
        }
    }
    
}