import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    }

}
 import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    }

} Main public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    } main {

    	Main main=new Main();

    	main.run();

    } Main main=new Main(); main new Main() main.run() main.run main String[] args args void run() {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    } run {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    } 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()-1;
    	} int i=0; int i=0; i 0 i<N i N i++ i++ i {
    		A[i]=sc.nextInt()-1;
    	} {
    		A[i]=sc.nextInt()-1;
    	} A[i]=sc.nextInt()-1 A[i] A i sc.nextInt()-1 sc.nextInt() sc.nextInt sc 1 int now=A[0]; now A[0] A 0 int next=0; next 0 int counter=0; counter 0 while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	} true {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	} counter++ counter if(now==1) {
    			break;
    		} now==1 now 1 {
    			break;
    		} break; next=A[now] next A[now] A now A[now]=-1 A[now] A now -1 1 if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		} next==-1 next -1 1 {
    			counter=-1;
    			break;
    		} counter=-1 counter -1 1 break; {
    			now=next;
    		} now=next now next System.out.println(counter) System.out.println System.out System System.out counter public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    }

} public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    }

} Main
import java.util.Scanner;




public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {
    	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()-1;
    	}

    	int now=A[0];
    	int next=0;

    	int counter=0;

    	while(true) {
    		counter++;

    		if(now==1) {
    			break;
    		}

    		next=A[now];

    		A[now]=-1;
    		
    		if(next==-1) {
    			counter=-1;
    			break;
    		}else {
    			now=next;
    		}

    	}


    	System.out.println(counter);


    }

}

