The Bovine Shuffle

Given a functional graph where each position i sends its cow to a_i, count the positions that hold at least one cow no matter how many shuffles are applied.

Medium6GraphDFSImplementationSimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Farmer John is convinced that happy cows give more milk, so he has hung a giant disco ball in his barn and wants to teach his cows to dance.

After looking up popular cow dances, Farmer John settles on the Bovine Shuffle. In the Bovine Shuffle his NN cows (1N1000001 \le N \le 100\,000) line up in a row and then perform one shuffle after another, and each shuffle can reorder the line. So the cows can find their own spots, Farmer John numbers the places in the row from 11 to NN. At the start each place holds exactly one cow.

One shuffle is described by NN numbers a1,,aNa_1, \ldots, a_N. When a shuffle happens, every cow standing at place ii moves to place aia_i. Each aia_i is between 11 and NN. All cows move to their new places at the same time. The values aia_i are not guaranteed to be distinct, so several cows can end up at the same place, and once cows share a place they move together for all remaining shuffles.

Farmer John notices that some places hold cows no matter how many shuffles take place. Count how many such places there are.

Input

The first line contains NN, the number of cows.

The second line contains the NN integers a1,,aNa_1, \ldots, a_N separated by spaces.

Output

Print on one line the number of places that always hold cows, no matter how many shuffles take place.