One of my acquaintances has a rather troublesome wife: no matter where he tries to hide his money, she always manages to find it and take it all. So, he is constantly searching for new hiding places. Their relationship evolved to the point where my friend decided to divide his money among several hiding places—at least this way, if his wife finds some of it, she won't find it all. A clever move.
However, a new question arises: where should he put the main part of his money, the stash he doesn't want his wife to find? Since she can check any hiding place with equal probability, my poor friend found only one solution: every day, he moves the money from one hiding place to another. He has to do this quickly (so his wife doesn't notice), which doesn't leave time to count the money each time—so he wrote down a transfer scheme on a piece of paper. To keep track of his capital, he noted the date when he created this scheme and numbered the hiding places, labeling the one with the main reserve for a "rainy day" as number "1."
But misfortune struck: he left the scheme unattended... and his wife immediately found it! She noticed his notes and decided to search for the largest hidden "stash." Using her unusual logic, she realized that sooner or later that stash would return to the first hiding place. Thus, she decided to calculate how many days it would take for all the hidden money to return to the places they were at on the day the scheme was created.
Regrettably, my acquaintance's wife asked me for help; and now, in turn, I ask you for assistance.
The first line contains the number of hiding places (0 < n < 15000). The second line contains a sequence of integers representing the transfer scheme, where the -th integer indicates the hiding place to which the contents of the -th hiding place are transferred each day.
Output a single integer—the number of days required for the contents of the hiding places to return to their original configuration.
Example 1