import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		Button b[] = new Button[n];
		for(int i = 0; i < n; i++){
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		}
		
		scan.close();
		int next = 0;
		int count = 0;
		
		while(true){
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		}
	}
}
class Button{
	int next;
	Boolean flag = true;
} import java.util.Scanner; Scanner java.util class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		Button b[] = new Button[n];
		for(int i = 0; i < n; i++){
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		}
		
		scan.close();
		int next = 0;
		int count = 0;
		
		while(true){
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		}
	}
} Main public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		Button b[] = new Button[n];
		for(int i = 0; i < n; i++){
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		}
		
		scan.close();
		int next = 0;
		int count = 0;
		
		while(true){
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		}
	} main {

		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		Button b[] = new Button[n];
		for(int i = 0; i < n; i++){
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		}
		
		scan.close();
		int next = 0;
		int count = 0;
		
		while(true){
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n; n n = scan.nextInt() n scan.nextInt() scan.nextInt scan Button b[] = new Button[n]; b new Button[n] n for(int i = 0; i < n; i++){
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		} {
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		} b[i] =  new Button() b[i] b i new Button() b[i].next = scan.nextInt()-1 b[i].next b[i] b i b[i].next scan.nextInt()-1 scan.nextInt() scan.nextInt scan 1 scan.close() scan.close scan int next = 0; next 0 int count = 0; count 0 while(true){
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		} true {
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		} b[next].flag = false b[next].flag b[next] b next b[next].flag false next = b[next].next next b[next].next b[next] b next b[next].next count++ count if(next == 1){
				System.out.print(count);
				break;
			} next == 1 next 1 {
				System.out.print(count);
				break;
			} System.out.print(count) System.out.print System.out System System.out count break; if(!b[next].flag){
				System.out.print("-1");
				break;
			} !b[next].flag b[next].flag b[next] b next b[next].flag {
				System.out.print("-1");
				break;
			} System.out.print("-1") System.out.print System.out System System.out "-1" break; String args[] args class Button{
	int next;
	Boolean flag = true;
} Button int next; next Boolean flag = true; flag true
import java.util.Scanner;

class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		
		Button b[] = new Button[n];
		for(int i = 0; i < n; i++){
			b[i] =  new Button();
			b[i].next = scan.nextInt()-1; 
		}
		
		scan.close();
		int next = 0;
		int count = 0;
		
		while(true){
			b[next].flag = false;
			next = b[next].next;
			count++;
			if(next == 1){
				System.out.print(count);
				break;
			}
			if(!b[next].flag){
				System.out.print("-1");
				break;
			}
		}
	}
}
class Button{
	int next;
	Boolean flag = true;
}