import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Deque;//push poll peek
import java.util.ArrayDeque;
import java.util.Queue;//add poll peek
import java.util.ArrayDeque;
import java.math.BigDecimal;

class Main{

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		int k = 0;
		int l;
		boolean flag = false;
		l = a[0] - 1;
		count += 1;
		while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		}
		if(!flag){
			System.out.println(-1);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Deque;//push poll peek Deque java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Queue;//add poll peek Queue java.util import java.util.ArrayDeque; ArrayDeque java.util import java.math.BigDecimal; BigDecimal java.math class Main{

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		int k = 0;
		int l;
		boolean flag = false;
		l = a[0] - 1;
		count += 1;
		while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		}
		if(!flag){
			System.out.println(-1);
		}
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		int k = 0;
		int l;
		boolean flag = false;
		l = a[0] - 1;
		count += 1;
		while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		}
		if(!flag){
			System.out.println(-1);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		int k = 0;
		int l;
		boolean flag = false;
		l = a[0] - 1;
		count += 1;
		while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		}
		if(!flag){
			System.out.println(-1);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] a = new int[n]; a new int[n] n for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(br.readLine());
		} {
			a[i] = Integer.parseInt(br.readLine());
		} a[i] = Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int count = 0; count 0 int k = 0; k 0 int l; l boolean flag = false; flag false l = a[0] - 1 l a[0] - 1 a[0] a 0 1 count += 1 count 1 while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		} count <= n count n {
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		} if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			} l == 1 l 1 {
				flag = true;
				System.out.println(count);
				break;
			} flag = true flag true System.out.println(count) System.out.println System.out System System.out count break; l = a[l] - 1 l a[l] - 1 a[l] a l 1 count += 1 count 1 if(!flag){
			System.out.println(-1);
		} !flag flag {
			System.out.println(-1);
		} System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Deque;//push poll peek
import java.util.ArrayDeque;
import java.util.Queue;//add poll peek
import java.util.ArrayDeque;
import java.math.BigDecimal;

class Main{

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(br.readLine());
		}
		int count = 0;
		int k = 0;
		int l;
		boolean flag = false;
		l = a[0] - 1;
		count += 1;
		while(count <= n){
			if(l == 1){
				flag = true;
				System.out.println(count);
				break;
			}
			l = a[l] - 1;
			count += 1;
		}
		if(!flag){
			System.out.println(-1);
		}
	}
}
