import java.util.Scanner;

public class Main{
  static int n;
  static int[] a;

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

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  }
} import java.util.Scanner; Scanner java.util public class Main{
  static int n;
  static int[] a;

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

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  }
} Main static int n; n static int[] a; a public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  } main {
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc a = new int[n] a new int[n] n for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 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 p = 1 p 1 count = 0; count 0 while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    } p != 2 && count <= n p != 2 p 2 count <= n count n {
      p = a[p - 1];
      ++count;
    } p = a[p - 1] p a[p - 1] a p - 1 p 1 ++count count if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    } p == 2 p 2 {
      System.out.println(count);
    } System.out.println(count) System.out.println System.out System System.out count {
      System.out.println(-1);
    } System.out.println(-1) System.out.println System.out System System.out -1 1 String[] args args public class Main{
  static int n;
  static int[] a;

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

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  }
} public class Main{
  static int n;
  static int[] a;

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

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  }
} Main
import java.util.Scanner;

public class Main{
  static int n;
  static int[] a;

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

    n = sc.nextInt();
    a = new int[n];
    for(int i = 0; i < n; i++){
      a[i] = sc.nextInt();
    }

    int p = 1, count = 0;
    while(p != 2 && count <= n){
      p = a[p - 1];
      ++count;
    }

    if(p == 2){
      System.out.println(count);
    }
    else{
      System.out.println(-1);
    }
  }
}
