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];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-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];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-1);}
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-1);}
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-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]; a new int[n] n int cnt = 0; cnt 0 int next = 0; next 0 boolean flag = false; flag false 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 if(a[0] == 2){cnt = 1; flag = true;} a[0] == 2 a[0] a 0 2 {cnt = 1; flag = true;} cnt = 1 cnt 1 flag = true flag true while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    } cnt < n && flag == false cnt < n cnt n flag == false flag false {
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    } next = a[next] - 1 next a[next] - 1 a[next] a next 1 cnt++ cnt if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      } a[next] == 2 a[next] a next 2 {
        cnt++;
        flag = true;
        break;
      } cnt++ cnt flag = true flag true break; if(flag){System.out.println(cnt);}
    else{System.out.println(-1);} flag {System.out.println(cnt);} System.out.println(cnt) System.out.println System.out System System.out cnt {System.out.println(-1);} 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 sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-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];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-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];
    int cnt = 0;
    int next = 0;
    boolean flag = false;

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

    if(a[0] == 2){cnt = 1; flag = true;}

    while(cnt < n && flag == false){
      next = a[next] - 1;
      cnt++;
      if(a[next] == 2){
        cnt++;
        flag = true;
        break;
      }
    }

    if(flag){System.out.println(cnt);}
    else{System.out.println(-1);}
  }
}