import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  }
} import java.util.*; util.* java import java.io.*; io.* java public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  }
} Main public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  } main {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(in.readLine()); N Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in int[] a = new int[N]; a new int[N] N for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      a[i] = Integer.parseInt(in.readLine());
    } {
      a[i] = Integer.parseInt(in.readLine());
    } a[i] = Integer.parseInt(in.readLine()) a[i] a i Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in int pointer = 0; pointer 0 int counter = 0; counter 0 for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    } int i=0; int i=0; i 0 i<N i N i++ i++ i {
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    } {
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    } pointer = a[pointer]-1 pointer a[pointer]-1 a[pointer] a pointer 1 counter++ counter if(pointer==1){
        System.out.println(counter);
        return;
      } pointer==1 pointer 1 {
        System.out.println(counter);
        return;
      } System.out.println(counter) System.out.println System.out System System.out counter 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) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  }
} public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  }
} Main
import java.util.*;
import java.io.*;

public class Main{
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int N = Integer.parseInt(in.readLine());
    int[] a = new int[N];
    for(int i=0;i<N;i++){
      a[i] = Integer.parseInt(in.readLine());
    }
    int pointer = 0;
    int counter = 0;
    for(int i=0;i<N;i++){
      pointer = a[pointer]-1;
      counter++;
      if(pointer==1){
        System.out.println(counter);
        return;
      }
    }
    System.out.println(-1);
  }
}
