import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  }
} import java.util.*; util.* java public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  } main {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  } 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+1]; a new int[N+1] N+1 N 1 for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    } int i = 1; int i = 1; i 1 i <= N i N i++ i++ i {
      a[i] = sc.nextInt();
    } {
      a[i] = sc.nextInt();
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int count = 0; count 0 int i = 1; i 1 while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    } i != 2 && a[i] != 0 i != 2 i 2 a[i] != 0 a[i] a i 0 {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    } int next = a[i]; next a[i] a i a[i] = 0 a[i] a i 0 i = next i next count++ count System.out.println(i == 2 ? count : -1) System.out.println System.out System System.out i == 2 ? count : -1 i == 2 i 2 count -1 1 String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  }
} Main
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] a = new int[N+1];
    for (int i = 1; i <= N; i++) {
      a[i] = sc.nextInt();
    }
    int count = 0;
    int i = 1;
    while (i != 2 && a[i] != 0) {
      int next = a[i];
      a[i] = 0;
      i = next;
      count++;
    }
    System.out.println(i == 2 ? count : -1);
  }
}