Skipper the squirrel has recently escaped his human owners, but being a new wild squirrel, Skipper is in dire need of nuts! Luckily for him, his mentor, Nibbles has buried nuts and maps at each of locations. Specifically, at location , Nibbles has hidden a nut and a map to location . So, whenever Skipper is at , he will collect the nut at that location (if he hadn't collected it before) and follow the map to location , and repeat. Skipper is currently at location . If Skipper repeats this process indefinitely, can you figure out how many nuts he collects?
Constraints
Input Specification
The first line contains two integers, and .
The second line contains integers, the -th of which corresponds to
Output Specifcation
One line with one integer, the number of nuts Skipper can collect by repeating his process indefinitely
Sample Input
7 4
5 4 1 3 6 4 2
Sample Output
5
Sample Explanation
Skipper starts at location , where he collects a nut and moves to location
At location , collects a nut at location and moves to location
Even if Skipper repeats this process indefinitely, he will only visit the locations , , , , and . Since he can only collect at most one nut at each location, Skipper can only collect nuts.
Comments