import java.util.*;

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

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

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n+1];
        for(int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        int[] b = new int[n+1];
        b[0] = 1;
        int i= 1;
        int ans = -1;
        while(i <= n) {
            b[i] = a[b[i-1]];
            if(b[i] == 2) {
                ans = i;
                break;
            }
            i++;
        }
        
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n+1];
        for(int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        int[] b = new int[n+1];
        b[0] = 1;
        int i= 1;
        int ans = -1;
        while(i <= n) {
            b[i] = a[b[i-1]];
            if(b[i] == 2) {
                ans = i;
                break;
            }
            i++;
        }
        
        System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] a = new int[n+1]; a new int[n+1] n+1 n 1 for(int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(sc.next());
        } int i=1; int i=1; i 1 i<=n i n i++ i++ i {
            a[i] = Integer.parseInt(sc.next());
        } {
            a[i] = Integer.parseInt(sc.next());
        } a[i] = Integer.parseInt(sc.next()) a[i] a i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] b = new int[n+1]; b new int[n+1] n+1 n 1 b[0] = 1 b[0] b 0 1 int i= 1; i 1 int ans = -1; ans -1 1 while(i <= n) {
            b[i] = a[b[i-1]];
            if(b[i] == 2) {
                ans = i;
                break;
            }
            i++;
        } i <= n i n {
            b[i] = a[b[i-1]];
            if(b[i] == 2) {
                ans = i;
                break;
            }
            i++;
        } b[i] = a[b[i-1]] b[i] b i a[b[i-1]] a b[i-1] b i-1 i 1 if(b[i] == 2) {
                ans = i;
                break;
            } b[i] == 2 b[i] b i 2 {
                ans = i;
                break;
            } ans = i ans i break; i++ i 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 = Integer.parseInt(sc.next());
        int[] a = new int[n+1];
        for(int i=1; i<=n; i++) {
            a[i] = Integer.parseInt(sc.next());
        }
        int[] b = new int[n+1];
        b[0] = 1;
        int i= 1;
        int ans = -1;
        while(i <= n) {
            b[i] = a[b[i-1]];
            if(b[i] == 2) {
                ans = i;
                break;
            }
            i++;
        }
        
        System.out.println(ans);
    }

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

} Main
import java.util.*;

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

}
