Manor Mystery
The gang has spotted a ghoulish ghost and are hot on its tail, but they need to cover their bases. This creepy critter is running as fast as he can, going in one room and through to the next, and isn't stopping. To catch him, the gang has decided to have the members stand guard, so that the ghoulish ghost will eventually run into them. What is the minimum number of members required to stand guard to that one of them will eventually encounter the frightening fiend?
The ghoulish ghost tears through the manor without stopping, entering room after room, always following the door ahead. Since the manor has finitely many rooms, the creepy critter must eventually find itself going in circles. The gang plans to station one member at each such loop, so that no matter which cycle the frightening fiend enters, someone will be waiting. What is the minimum number of members needed?
Input
The first line contains a single integer (
) - the number of doors in the manor.
The second line contains integers
(
) -
is the room the
th door leads to, and all
are distinct.
Output
- The number of members required to stand guard
Example
Input 1
4
1 2 0 3
Output 1
2
One member can be put on any of indices , and one on
.
Comments