import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        }
        int p = 0;
        int np;
        int cnt = 0;
        while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        }
    }

    public static void main(String[] args) {
        new Main();
    }
} import java.math.BigInteger; BigInteger java.math import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Collections; Collections java.util import java.util.Comparator; Comparator java.util import java.util.HashMap; HashMap java.util import java.util.HashSet; HashSet java.util import java.util.Iterator; Iterator java.util import java.util.List; List java.util import java.util.Map.Entry; Entry java.util.Map import java.util.PriorityQueue; PriorityQueue java.util import java.util.Scanner; Scanner java.util class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        }
        int p = 0;
        int np;
        int cnt = 0;
        while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        }
    }

    public static void main(String[] args) {
        new Main();
    }
} Main static final int MOD = 1000000007; MOD 1000000007 static final int INF = 1 << 30; INF 1 << 30 1 30 Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        }
        int p = 0;
        int np;
        int cnt = 0;
        while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        }
    } Main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        }
        int p = 0;
        int np;
        int cnt = 0;
        while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        }
    } 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++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            int num = sc.nextInt() - 1;
            a[i] = num;
        } {
            int num = sc.nextInt() - 1;
            a[i] = num;
        } int num = sc.nextInt() - 1; num sc.nextInt() - 1 sc.nextInt() sc.nextInt sc 1 a[i] = num a[i] a i num int p = 0; p 0 int np; np int cnt = 0; cnt 0 while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        } true {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        } cnt++ cnt np = a[p] np a[p] a p if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            } np == -1 np -1 1 {
                System.out.println(-1);
                return;
            } System.out.println(-1) System.out.println System.out System System.out -1 1 return; if (np == 1) {
                System.out.println(cnt);
                return;
            } np == 1 np 1 {
                System.out.println(cnt);
                return;
            } System.out.println(cnt) System.out.println System.out System System.out cnt return; a[p] = -1 a[p] a p -1 1 p = np p np public static void main(String[] args) {
        new Main();
    } main {
        new Main();
    } new Main() String[] args args
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    Main() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        for (int i = 0; i < N; i++) {
            int num = sc.nextInt() - 1;
            a[i] = num;
        }
        int p = 0;
        int np;
        int cnt = 0;
        while (true) {
            cnt++;
            np = a[p];
            if (np == -1) {
                System.out.println(-1);
                return;
            } else if (np == 1) {
                System.out.println(cnt);
                return;
            }
            a[p] = -1;
            p = np;
        }
    }

    public static void main(String[] args) {
        new Main();
    }
}
