import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  }
} import java.util.Scanner; Scanner 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];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  } 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++ ) {
      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 b = 1; b 1 int c = 0; c 0 int d = 0; d 0 while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    } b != 2 b 2 {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    } d += 1 d 1 c = b c b b = a[b-1] b a[b-1] a b-1 b 1 if ( b == 0 ) {
        System.out.println(-1);
        return;
      } b == 0 b 0 {
        System.out.println(-1);
        return;
      } System.out.println(-1) System.out.println System.out System System.out -1 1 return; a[c-1] = 0 a[c-1] a c-1 c 1 0 System.out.println(d) System.out.println System.out System System.out d 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];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  }
} Main
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    for (int i = 0; i<n; i++ ) {
      a[i] = sc.nextInt();
    }
    int b = 1;
    int c = 0;
    int d = 0;

    while ( b != 2 ) {
      d += 1;
      c = b;
      b = a[b-1];
      if ( b == 0 ) {
        System.out.println(-1);
        return;
      }
      a[c-1] = 0;
    }
    System.out.println(d);
  }
}