import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  }
} import java.util.*; util.* java public class Main{
  
  public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  }
} Main public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  } main {
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  } Scanner scanner = new Scanner (System.in); scanner new Scanner (System.in) int totalButton = scanner.nextInt(); totalButton scanner.nextInt() scanner.nextInt scanner Integer[] buttonList = new Integer[totalButton+1]; buttonList new Integer[totalButton+1] totalButton+1 totalButton 1 for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    } int buttonNum=0; int buttonNum=0; buttonNum 0 buttonNum<totalButton buttonNum totalButton buttonNum++ buttonNum++ buttonNum {
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    } {
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    } int temp = scanner.nextInt(); temp scanner.nextInt() scanner.nextInt scanner buttonList[buttonNum+1]=temp buttonList[buttonNum+1] buttonList buttonNum+1 buttonNum 1 temp int nowButton=1; nowButton 1 boolean flag = false; flag false int num; num for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    } num=0; num=0 num 0 num<totalButton num totalButton num++ num++ num {
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    } {
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    } int temp = buttonList[nowButton]; temp buttonList[nowButton] buttonList nowButton nowButton=temp nowButton temp if (nowButton==2){
        flag=true;
        num++;
        break;
      } nowButton==2 nowButton 2 {
        flag=true;
        num++;
        break;
      } flag=true flag true num++ num break; if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    } flag==true flag true {
      System.out.println(num);
    } System.out.println(num) System.out.println System.out System System.out num {
      System.out.println("-1");
    } System.out.println("-1") System.out.println System.out System System.out "-1" String[] args args public class Main{
  
  public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  }
} public class Main{
  
  public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  }
} Main
import java.util.*;

public class Main{
  
  public static void main(String[] args){
    
  Scanner scanner = new Scanner (System.in);
  
  	int totalButton = scanner.nextInt();
    
    Integer[] buttonList = new Integer[totalButton+1];
    
    for (int buttonNum=0; buttonNum<totalButton; buttonNum++){
      int temp = scanner.nextInt();
      buttonList[buttonNum+1]=temp;
    }
    int nowButton=1;
    boolean flag = false;
    int num;
    for(num=0; num<totalButton; num++){
      int temp = buttonList[nowButton];
      nowButton=temp;
      
      if (nowButton==2){
        flag=true;
        num++;
        break;
      }
    }
    if (flag==true){
      System.out.println(num);
    } else {
      System.out.println("-1");
    }
  }
}