import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	} main {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m m cnt = 1; cnt 1 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 m = a[0] m a[0] a 0 while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		} m != 2 m 2 {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		} m = a[m-1] m a[m-1] a m-1 m 1 cnt++ cnt if(cnt > n) {
				cnt = -1;
				break;
			} cnt > n cnt n {
				cnt = -1;
				break;
			} cnt = -1 cnt -1 1 break; System.out.print(cnt) System.out.print System.out System System.out cnt String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	}

} Main
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m , cnt = 1;
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		m = a[0];
		while(m != 2) {
			m = a[m-1];
			cnt++;
			if(cnt > n) {
				cnt = -1;
				break;
			}
		}
		System.out.print(cnt);
		
		
	}

}