Strange people live on Sunny Island, and every morning each of them gives their unique shoes to their best and only friend. Different people have different best friends. After a certain number of days, they are finally happy to learn that all footwear has returned to its original owners. However, they have already forgotten how many days have passed since the last such joyous day, so they ask you, the cleverest programmer, to find the minimum possible number of days until their next holiday.
The input data contains several test cases. Each test case consists of an integer (0 < N < 6001), indicating the number of people living on the island. The next line of each test case contains integers (from to ), indicating the best friend of each -th person living on the island.
For each test case, output on a separate line the smallest possible number of days between holidays.
Example 1