import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	}
} import java.util.*; util.* java import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	} main {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] b = new int[n]; b new int[n] n for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    b[i] = sc.nextInt()-1;
		} {
		    b[i] = sc.nextInt()-1;
		} b[i] = sc.nextInt()-1 b[i] b i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int result = -1; result -1 1 int index = 0; index 0 int next = 0; next 0 for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		} {
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		} if(b[index] < 0) break; b[index] < 0 b[index] b index 0 break; if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    } b[index] == 1 b[index] b index 1 {
		        result = i+1;
		        break;
		    } result = i+1 result i+1 i 1 break; {
		        next = b[index];
		        b[index] = -1;
		    } next = b[index] next b[index] b index b[index] = -1 b[index] b index -1 1 index = next index next System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	}
} Main
import java.util.*;
import static java.lang.Math.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[] b = new int[n];
		for(int i = 0; i < n; i++){
		    b[i] = sc.nextInt()-1;
		}
		
		// 計算
		int result = -1;
		int index = 0;
		int next = 0;
		for(int i = 0; i < n; i++){
		    if(b[index] < 0) break;
		    if(b[index] == 1){
		        result = i+1;
		        break;
		    }else{
		        next = b[index];
		        b[index] = -1;
		    }
		    index = next;
		}
		
		
		// 出力
		System.out.println(result);
	}
}
