import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 }
} import java.util.Scanner; Scanner java.util public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 }
} Main public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 } main {
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] a = new int[N]; a new int[N] N for(int i =0;i<N;i++) a[i] =sc.nextInt(); int i =0; int i =0; i 0 i<N i N i++ i++ i a[i] =sc.nextInt(); a[i] =sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc boolean br = true; br true int tmp = 1; tmp 1 int ans = -1; ans -1 1 for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   } int i=1; int i=1; i 1 i<=100000 i 100000 i++ i++ i {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   } {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   } tmp=a[tmp-1] tmp a[tmp-1] a tmp-1 tmp 1 if(tmp==2)
     {
       ans = i;
       break;
     } tmp==2 tmp 2 {
       ans = i;
       break;
     } ans = i ans i break; System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 }
} public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 }
} Main
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[] a = new int[N];
   for(int i =0;i<N;i++) a[i] =sc.nextInt();
   boolean br = true;
   int tmp = 1;
   int ans = -1;
   
   for(int i=1;i<=100000;i++)
   {
     tmp=a[tmp-1];
     if(tmp==2)
     {
       ans = i;
       break;
     }
   }
   System.out.println(ans);
 }
}