
import java.util.Scanner;

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

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

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

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

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

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] button = new int[n]; button new int[n] n for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < button.length i button.length button button.length i++ i++ i {
			button[i] = sc.nextInt();
		} {
			button[i] = sc.nextInt();
		} button[i] = sc.nextInt() button[i] button i sc.nextInt() sc.nextInt sc int next = 0; next 0 int cnt = 0; cnt 0 for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		} int i = 1; int i = 1; i 1 i = next i = next i next {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		} {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		} next = button[i - 1] next button[i - 1] button i - 1 i 1 cnt++ cnt if (next == 2) {
				break;
			} next == 2 next 2 {
				break;
			} break; if (cnt > n) {
				cnt = -1;
				break;
			} cnt > n cnt n {
				cnt = -1;
				break;
			} cnt = -1 cnt -1 1 break; System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

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

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

	}
} Main

import java.util.Scanner;

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

		int[] button = new int[n];
		for (int i = 0; i < button.length; i++) {
			button[i] = sc.nextInt();
		}
		
		int next = 0;
		int cnt = 0;
		for (int i = 1;; i = next) {
			next = button[i - 1];
			cnt++;
			if (next == 2) {
				break;
			}
			
			if (cnt > n) {
				cnt = -1;
				break;
			}
			
		}
		System.out.println(cnt);

	}
}