

import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	}
} import java.util.Scanner; Scanner java.util public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	}
} Main public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	} main {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	} new Main().start() new Main().start new Main() String[] args args void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	} start {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = in.nextInt();
		} {
			a[i] = in.nextInt();
		} a[i] = in.nextInt() a[i] a i in.nextInt() in.nextInt in int count = 0; count 0 int i = 0; i 0 while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		} true {
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		} if(i == 1){
				break;
			}else if(count > 100000){
				break;
			} i == 1 i 1 {
				break;
			} break; if(count > 100000){
				break;
			} count > 100000 count 100000 {
				break;
			} break; i = a[i]-1 i a[i]-1 a[i] a i 1 count++ count if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		} count != 100001 count 100001 {
			System.out.println(count);
		} System.out.println(count) System.out.println System.out System System.out count {
			System.out.println(-1);
		} System.out.println(-1) System.out.println System.out System System.out -1 1 in.close() in.close in public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	}
} public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	}
} Main


import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		new Main().start();
	}
	void start(){
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = in.nextInt();
		}
		int count = 0;
		int i = 0;
		while(true){
			if(i == 1){
				break;
			}else if(count > 100000){
				break;
			}
			i = a[i]-1;
			count++;
		}
		if(count != 100001){
			System.out.println(count);
		}else{
			System.out.println(-1);
		}
		in.close();
	}
}
