import java.util.*;
public class Main{
	static int Train(int[] s, int t){
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	}
			

	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() - 1;
		}
		System.out.println(Train(a, n));
	}
} import java.util.*; util.* java public class Main{
	static int Train(int[] s, int t){
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	}
			

	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() - 1;
		}
		System.out.println(Train(a, n));
	}
} Main static int Train(int[] s, int t){
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	} Train {
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	} int count = 0; count 0 int x = 0; x 0 int y = 0; y 0 for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		} int i=0; int i=0; i 0 i<t i t i++ i++ i {
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		} {
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		} count++ count y = s[x] y s[x] s x x = y x y if(x==1)return count; x==1 x 1 return count; count return -1; -1 1 int[] s s int t t 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() - 1;
		}
		System.out.println(Train(a, n));
	} 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() - 1;
		}
		System.out.println(Train(a, n));
	} 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() - 1;
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i] = sc.nextInt() - 1;
		} {
			a[i] = sc.nextInt() - 1;
		} a[i] = sc.nextInt() - 1 a[i] a i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 System.out.println(Train(a, n)) System.out.println System.out System System.out Train(a, n) Train a n String[] args args public class Main{
	static int Train(int[] s, int t){
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	}
			

	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() - 1;
		}
		System.out.println(Train(a, n));
	}
} public class Main{
	static int Train(int[] s, int t){
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	}
			

	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() - 1;
		}
		System.out.println(Train(a, n));
	}
} Main
import java.util.*;
public class Main{
	static int Train(int[] s, int t){
		int count = 0;
		int x = 0;
      	int y = 0;
		for(int i=0; i<t; i++){
			count++;
			y = s[x];
          	x = y;
			if(x==1)return count;
		}
		return -1;
	}
			

	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() - 1;
		}
		System.out.println(Train(a, n));
	}
}