import java.util.BitSet;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	}
	

	

} import java.util.BitSet; BitSet java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	}
	

	

} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	} main {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int n = Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line int a[] = new int[n+1]; a new int[n+1] n+1 n 1 for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		} {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		} line = sc.nextLine() line sc.nextLine() sc.nextLine sc a[i] = Integer.parseInt(line) a[i] a i Integer.parseInt(line) Integer.parseInt Integer line BitSet bits = new BitSet(); bits new BitSet() int current = 1; current 1 bits.set(1) bits.set bits 1 int count = 0; count 0 while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        } true {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        } count++ count int next = a[current]; next a[current] a current if (next == 2) {
        		System.out.println(count);
        		return;
        	} next == 2 next 2 {
        		System.out.println(count);
        		return;
        	} System.out.println(count) System.out.println System.out System System.out count return; if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	} bits.get(next) bits.get bits next {
        		System.out.println(-1);
        		return;
        	} System.out.println(-1) System.out.println System.out System System.out -1 1 return; {
        		bits.set(next);
        	} bits.set(next) bits.set bits next current = next current next String[] args args public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	}
	

	

} public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	}
	

	

} Main
import java.util.BitSet;
import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();

        
        int n = Integer.parseInt(line);
        
        int a[] = new int[n+1];
        
        for (int i = 1; i <= n; i++) {
        	line = sc.nextLine();
			a[i] = Integer.parseInt(line);
		}
        
        BitSet bits = new BitSet();
        
        int current = 1;	// Button 1 on
        bits.set(1);	// button 1 on
        int count = 0;

        while (true) {
        	count++;
        	int next = a[current];
        	
        	if (next == 2) {
        		System.out.println(count);
        		return;
        	}
        	
        	if (bits.get(next)) {
        		System.out.println(-1);
        		return;
        	} else {
        		bits.set(next);
        	}
        	
        	current = next;
        }
        
        
        
	}
	

	

}
