import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  }
} import java.util.*; util.* java public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  } main {
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n=sc.nextInt() n sc.nextInt() sc.nextInt sc f=0 f 0 i=0; i 0 int[] a=new int[n] a new int[n] n b=new int[n]; b new int[n] n b[0]=1 b[0] b 0 1 for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    } int j=0; int j=0; j 0 j<n j n j++ j++ j {
      a[j]=sc.nextInt();
    } {
      a[j]=sc.nextInt();
    } a[j]=sc.nextInt() a[j] a j sc.nextInt() sc.nextInt sc while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    } f<n f n {
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    } b[i]=0 b[i] b i 0 b[a[i]-1]++ b[a[i]-1] b a[i]-1 a[i] a i 1 f++ f i=a[i]-1 i a[i]-1 a[i] a i 1 if(i==1){
        System.out.println(f);
        break;
      } i==1 i 1 {
        System.out.println(f);
        break;
      } System.out.println(f) System.out.println System.out System System.out f break; if(f==n){
      System.out.println(-1);
    } f==n f n {
      System.out.println(-1);
    } System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  }
} public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  }
} Main
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),f=0,i=0;
    int[] a=new int[n],b=new int[n];
    b[0]=1;
    for(int j=0;j<n;j++){
      a[j]=sc.nextInt();
    }
    while(f<n){
      b[i]=0;
      b[a[i]-1]++;
      f++;
      i=a[i]-1;
      if(i==1){
        System.out.println(f);
        break;
      }
    }
    if(f==n){
      System.out.println(-1);
    }
  }
}
