810. Corners

0

Medium

Corners is a game commonly played in the Eastern states of India. It involves 4 or more players, each occupying a corner of a polygon. One player, known as the 'Tat', is chosen and must go to another corner, as directed by a player already occupying a corner. While the 'Tat' is on their way to the redirected corner, the other players try to exchange their spots, and the 'Tat' tries to capture a corner, leaving someone else as the new 'Tat'. This game is similar to Musical Chairs. Mili was playing Corners with her friends and wondered if it's possible for the 'Tat' to get stuck in an infinite loop. She wants to find the loop with the maximum number of corners. It's important to note that a player may redirect the 'Tat' to themselves, creating a loop with a single corner.

Input Format

The first line of input contains an integer N, representing the number of corners. The next line contains N space-separated integers, each ranging from 0 to N-1. Each integer represents the index or position where a player would redirect the 'Tat'. It's important to note that each value is unique.

Output Format

Print the number of corners in the longest loop.

Example

Input

7 5 4 0 3 1 6 2

Output

4

Constraints

1 <= N <= 10^5 1 <= A_i < N