import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	int[] a = new int[n];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    System.out.println(count);
	}
    }
} import java.util.Scanner; Scanner 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];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    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];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    System.out.println(count);
	}
    } main {
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	int[] a = new int[n];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    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 for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    a[i] = scan.nextInt()-1;
	} {
	    a[i] = scan.nextInt()-1;
	} a[i] = scan.nextInt()-1 a[i] a i scan.nextInt()-1 scan.nextInt() scan.nextInt scan 1 int i = 0; i 0 int count = 1; count 1 while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	} true {
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	} if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    } a[i] == 1 a[i] a i 1 {
		break;
	    } break; if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    } a[i] == -1 a[i] a i -1 1 {
		break;
	    } break; {
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    } int tmp = i; tmp i i = a[i] i a[i] a i a[tmp] = -1 a[tmp] a tmp -1 1 count++ count if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    System.out.println(count);
	} a[i] == -1 a[i] a i -1 1 {
	    System.out.println(-1);
	} System.out.println(-1) System.out.println System.out System System.out -1 1 {
	    System.out.println(count);
	} 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];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    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];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    System.out.println(count);
	}
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	int n = scan.nextInt();
	int[] a = new int[n];
	for(int i = 0; i < n; i++){
	    a[i] = scan.nextInt()-1;
	}

	int i = 0;
	int count = 1;
	while(true){
	    if(a[i] == 1){
		break;
	    }else if(a[i] == -1){
		break;
	    }else{
		int tmp = i;
		i = a[i];
		a[tmp] = -1;
		count++;
	    }
	}

	if(a[i] == -1){
	    System.out.println(-1);
	}else{
	    System.out.println(count);
	}
    }
}
