import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	}
} import java.util.*; util.* java import java.io.PrintWriter; PrintWriter java.io import static java.lang.Integer.*; import static java.lang.Integer.*; import static java.lang.Integer.*; import static java.lang.Long.parseLong; import static java.lang.Long.parseLong; import static java.lang.Long.parseLong; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	}
} Main public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	} main {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	} int i i j; j Scanner sc = new Scanner(in); sc new Scanner(in) int n = parseInt(sc.next()); n parseInt(sc.next()) parseInt sc.next() sc.next sc int[] a = new int[n]; a new int[n] n for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		} i=0; i=0 i 0 i<n i n i++ i++ i {
			a[i] = parseInt(sc.next());
		} {
			a[i] = parseInt(sc.next());
		} a[i] = parseInt(sc.next()) a[i] a i parseInt(sc.next()) parseInt sc.next() sc.next sc sc.close() sc.close sc boolean[] f = new boolean[n]; f new boolean[n] n int cnt=0; cnt 0 i=0 i 0 while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		} f[i]==false&&i!=1 f[i]==false f[i] f i false i!=1 i 1 {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		} f[i]=true f[i] f i true i=a[i]-1 i a[i]-1 a[i] a i 1 cnt++ cnt out.println(i==1?cnt:-1) out.println out i==1?cnt:-1 i==1 i 1 cnt -1 1 String[] args args public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	}
} public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	}
} Main
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.parseLong;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		int[] a = new int[n];
		for(i=0;i<n;i++) {
			a[i] = parseInt(sc.next());
		}
		sc.close();
		boolean[] f = new boolean[n];
		int cnt=0;
		i=0;
		while(f[i]==false&&i!=1) {
			f[i]=true;
			i=a[i]-1;
			cnt++;
		}
		out.println(i==1?cnt:-1);
	}
}
