Islands#11826

Islands

1 second
256 megabytes
Hard

There are islands, numbered from to N - 1. A famous mariner, Gama-da-Vasco, resides on the island labeled . From each island, there is at most one route to another island, meaning from island you can only go to island numbered a_i (-1 \le a_i < N). If a_i = -1, then there is no path from the -th island to any other; otherwise, the path leads from the -th island to the a_i-th island.

Thus, a system of one-way passages is formed: from each island, you can move further in only one way. To reach certain islands, Gama-da-Vasco must pass through intermediaries, and some islands may be completely unreachable from island .

However, he has a special privilege: he can change one route — that is, change the value of any a_i to another arbitrary number from to N - 1.

What is the maximum number of different islands that Gama-da-Vasco can visit, starting from island and making one such change?

Input

In a single line of the input file, first comes the number (1 \le N \le 2 \cdot 10^5), followed by exactly numbers a_i (-1 \le a_i < N). If a_i = -1, then there is no path from the -th island to any other; otherwise, the path leads from the -th island to the a_i-th island.

Output

Output a single number - the maximum number of different islands that can be visited.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading