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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	}
} import java.util.HashSet; HashSet java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int next = 1; next 1 int[] a = new int[n]; a new int[n] n HashSet<Integer> hSet = new HashSet<>(); hSet new HashSet<>() for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = scanner.nextInt();
		} {
			a[i] = scanner.nextInt();
		} a[i] = scanner.nextInt() a[i] a i scanner.nextInt() scanner.nextInt scanner for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		} {
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		} next = a[next-1] next a[next-1] a next-1 next 1 if(next == 2){
				System.out.println(i+1);
				return;
			} next == 2 next 2 {
				System.out.println(i+1);
				return;
			} System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 return; if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			} hSet.contains(next) hSet.contains hSet next {
				System.out.println(-1);
				return;
			} System.out.println(-1) System.out.println System.out System System.out -1 1 return; {
				hSet.add(next);
			} hSet.add(next) hSet.add hSet next String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	}
} Main
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int next = 1;
		int[] a = new int[n];
		HashSet<Integer> hSet = new HashSet<>();

		for(int i = 0; i < n; i++){
			a[i] = scanner.nextInt();
		}

		for(int i = 0; i < n; i++){
			next = a[next-1];
			//System.out.println("next" + next);
			if(next == 2){
				System.out.println(i+1);
				return;
			}
			if(hSet.contains(next)){
				System.out.println(-1);
				return;
			}else {
				hSet.add(next);
			}

		}
	}
}