import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    } main {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    } 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<a.length;i++)
        {
            a[i] = scan.nextInt();
        } int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
            a[i] = scan.nextInt();
        } {
            a[i] = scan.nextInt();
        } a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan int tmp = 1; tmp 1 for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        } int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        } {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        } tmp = a[tmp-1] tmp a[tmp-1] a tmp-1 tmp 1 if(tmp==2)
            {
                System.out.println(i+1);
                return;
            } tmp==2 tmp 2 {
                System.out.println(i+1);
                return;
            } System.out.println(i+1) System.out.println System.out System System.out i+1 i 1 return; 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) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int n = scan.nextInt();
        int[] a = new int[n];
        for(int i=0;i<a.length;i++)
        {
            a[i] = scan.nextInt();
        }
        
        int tmp = 1;
        for(int i=0;i<a.length;i++)
        {
            tmp = a[tmp-1];
            if(tmp==2)
            {
                System.out.println(i+1);
                return;
            }
        }
        System.out.println(-1);
    }
}