import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void solve() throws IOException {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {

	public static void solve() throws IOException {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} Main public static void solve() throws IOException {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	} solve {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	} 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();
		} 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 sc.close() sc.close sc int cnt = 0; cnt 0 int id = 0; id 0 for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		} {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		} if (id == 1) {
				System.out.println(cnt);
				return;
			} id == 1 id 1 {
				System.out.println(cnt);
				return;
			} System.out.println(cnt) System.out.println System.out System System.out cnt return; cnt++ cnt id = a[id] - 1 id a[id] - 1 a[id] a id 1 System.out.println(-1) System.out.println System.out System System.out -1 1 return; public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	} main {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	} try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			solve();
		} solve() solve String[] args args public class Main {

	public static void solve() throws IOException {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} public class Main {

	public static void solve() throws IOException {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} Main
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void solve() throws IOException {
		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();
		}
		sc.close();

		int cnt = 0;
		int id = 0;
		for (int i = 0; i < n; i++) {
			if (id == 1) {
				System.out.println(cnt);
				return;
			}
			cnt++;
			id = a[id] - 1;
		}
		System.out.println(-1);
		return;
	}

	public static void main(String[] args) {
		try {
			solve();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}