import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	}
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util import java.util.Set; Set java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a = new int[n]; a new int[n] n int i = 0; i 0 for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		} i = 0; i = 0 i 0 i < n i n i++ i++ i {
			a[i] = scan.nextInt();
		} {
			a[i] = scan.nextInt();
		} a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan int button = 0; button 0 Set<Integer> set = new HashSet<Integer>(); set new HashSet<Integer>() int count = 0; count 0 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	}
} Main
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	}
}