import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  }
} import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  }
} Main public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  } main {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] a = new int[N]; a new int[N] N for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1; int i = 0; int i = 0; i 0 i < N i N i++ i++ i a[i] = scanner.nextInt() - 1; a[i] = scanner.nextInt() - 1 a[i] a i scanner.nextInt() - 1 scanner.nextInt() scanner.nextInt scanner 1 int next = 0; next 0 for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    } int cnt = 1; int cnt = 1; cnt 1 cnt <= N cnt N cnt++ cnt++ cnt {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    } {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    } next = a[next] next a[next] a next if (next == 1) {
        System.out.println(cnt);
        return;
      } next == 1 next 1 {
        System.out.println(cnt);
        return;
      } System.out.println(cnt) System.out.println System.out System System.out cnt 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) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  }
} Main
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt() - 1;
    int next = 0;
    for (int cnt = 1; cnt <= N; cnt++) {
      next = a[next];
      if (next == 1) {
        System.out.println(cnt);
        return;
      }
    }
    System.out.println(-1);
  }
}
