import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}
 import java.util.*; util.* java import java.math.*; math.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 int[] ar = new int[n]; ar new int[n] n boolean[] b = new boolean[n]; b new boolean[n] n for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        } {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        } ar[i] = sc.nextInt() - 1 ar[i] ar i sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 b[i] = false b[i] b i false int num = ar[0]; num ar[0] ar 0 while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        } true {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        } if (b[num] || b[1]) {
                break;
            } b[num] || b[1] b[num] b num b[1] b 1 {
                break;
            } break; b[num] = true b[num] b num true num = ar[num] num ar[num] ar num cnt++ cnt System.out.println(b[1]?cnt:-1) System.out.println System.out System System.out b[1]?cnt:-1 b[1] b 1 cnt -1 1 sc.close() sc.close sc String[] args args class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

} io public static void br() {
        System.out.println("");
    } br {
        System.out.println("");
    } System.out.println("") System.out.println System.out System System.out "" public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    } YesNo {
        System.out.println(f ? "Yes" : "No");
    } System.out.println(f ? "Yes" : "No") System.out.println System.out System System.out f ? "Yes" : "No" f "Yes" "No" boolean f f public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    } YESNO {
        System.out.println(f ? "YES" : "NO");
    } System.out.println(f ? "YES" : "NO") System.out.println System.out System System.out f ? "YES" : "NO" f "YES" "NO" boolean f f class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


} Algo public static boolean isOdd(int n) {
        return n % 2 == 1;
    } isOdd {
        return n % 2 == 1;
    } return n % 2 == 1; n % 2 == 1 n % 2 n 2 1 int n n public static boolean isEven(int n) {
        return n % 2 == 0;
    } isEven {
        return n % 2 == 0;
    } return n % 2 == 0; n % 2 == 0 n % 2 n 2 0 int n n public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    }
} Main
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int cnt = 0;
        int[] ar = new int[n];
        boolean[] b = new boolean[n];
        for (int i = 0; i < n; i++) {
            ar[i] = sc.nextInt() - 1;
            b[i] = false;
        }
        int num = ar[0];
        while (true) {
            if (b[num] || b[1]) {
                break;
            }
            b[num] = true;
            num = ar[num];
            cnt++;
        }
        System.out.println(b[1]?cnt:-1);
        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}

