import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	}
} import java.util.*; util.* java public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	}
} Main public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	} main {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int lamp[] = new int[n+1]; lamp new int[n+1] n+1 n 1 lamp[0] = -1 lamp[0] lamp 0 -1 1 for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      } int i = 1; int i = 1; i 1 i < n+1 i n+1 n 1 i++ i++ i {
      lamp[i] = in.nextInt();
      } {
      lamp[i] = in.nextInt();
      } lamp[i] = in.nextInt() lamp[i] lamp i in.nextInt() in.nextInt in int now = lamp[1]; now lamp[1] lamp 1 int co = 0; co 0 for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      } {
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      } if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        } now==2 now 2 {
          	co++;
        	break;
        } co++ co break; {
        now = lamp[now];
        co++;
        } now = lamp[now] now lamp[now] lamp now co++ co if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);} co>n-1 co n-1 n 1 {System.out.print(-1);} System.out.print(-1) System.out.print System.out System System.out -1 1 {System.out.print(co);} System.out.print(co) System.out.print System.out System System.out co String[] args args public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	}
} public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	}
} Main
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
      	int lamp[] = new int[n+1];
      
      lamp[0] = -1;
      for(int i = 1;i < n+1;i++){
      lamp[i] = in.nextInt();
      }
      
      int now = lamp[1];int co = 0;
      for(int i = 0;i<n;i++){
        if(now==2){
          	co++;
        	break;
        }else{
        now = lamp[now];
        co++;
        }
      }
      if(co>n-1){System.out.print(-1);}
      else{System.out.print(co);}
      
	}
}
