import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	}
} 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[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int nowon = 1; nowon 1 int count = 0; count 0 for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		} {
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		} if (nowon == 2){
				break;
			} nowon == 2 nowon 2 {
				break;
			} break; nowon = a[nowon-1] nowon a[nowon-1] a nowon-1 nowon 1 count++ count if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		} count == n count n {
			System.out.println(-1);
		} System.out.println(-1) System.out.println System.out System System.out -1 1 {
			System.out.println(count);			
		} System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i=0; i<n; i++){
			a[i] = sc.nextInt();
		}
		
		int nowon = 1;
		int count = 0;
		
		for(int i=0; i<n; i++){
			if (nowon == 2){
				break;
			}
			nowon = a[nowon-1];
			count++;
		}
		
		if (count == n){
			System.out.println(-1);
		}
		else{
			System.out.println(count);			
		}
		
		sc.close();
	}
}
