import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
} Main public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    } main {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    } try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           } catch (IOException e) {
            e.printStackTrace();
           } IOException e {
            e.printStackTrace();
           } e.printStackTrace() e.printStackTrace e {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int a[] = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                a[i] = Integer.parseInt(br.readLine());
            } {
                a[i] = Integer.parseInt(br.readLine());
            } a[i] = Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int now = a[0]; now a[0] a 0 int count = 1; count 1 boolean flag = false; flag false while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            } count < n count n {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            } if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                } now == 2 now 2 {
                    System.out.println(count);
                    flag = true;
                    break;
                } System.out.println(count) System.out.println System.out System System.out count flag = true flag true break; now = a[now - 1] now a[now - 1] a now - 1 now 1 count++ count if (!flag) {
                System.out.println(-1);
            } !flag flag {
                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) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
} public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            int n = Integer.parseInt(br.readLine());
            int a[] = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(br.readLine());
            }
            int now = a[0];
            int count = 1;
            boolean flag = false;
            while (count < n) {
                if (now == 2) {
                    System.out.println(count);
                    flag = true;
                    break;
                }
                now = a[now - 1];
                count++;
            }
            if (!flag) {
                System.out.println(-1);
            }
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}