import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.HashSet; HashSet java.util import java.util.Set; Set java.util public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int a[] = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(br.readLine());
		} {
			a[i] = Integer.parseInt(br.readLine());
		} a[i] = Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int now = 1; now 1 Set<Integer> set = new HashSet<>(); set new HashSet<>() set.add(1) set.add set 1 for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		} int i = 0; int i = 0; i 0 i++ i++ i {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		} {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		} now = a[now - 1] now a[now - 1] a now - 1 now 1 if (set.contains(now)) {
				System.out.println("-1");
				return;
			} set.contains(now) set.contains set now {
				System.out.println("-1");
				return;
			} System.out.println("-1") System.out.println System.out System System.out "-1" return; if (now == 2) {
				System.out.println(i + 1);
				return;
			} now == 2 now 2 {
				System.out.println(i + 1);
				return;
			} System.out.println(i + 1) System.out.println System.out System System.out i + 1 i 1 return; set.add(now) set.add set now String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	}
} public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	}
}