Problem2252-- Takahashi's Secret

2252: Takahashi's Secret

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MB

Description

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 200200 points

Problem Statement

Takahashi has NN friends. They have nicknames: Friend 11, Friend 22\ldots, Friend NN.
One day, Takahashi accidentally let one of his friends, Friend XX, learn his shameful secret.
For each i = 1, 2, \ldots, Ni=1,2,,N, when Friend ii learns the secret, he/she will share it with Friend A_iAi, if Friend A_iAi has not already learned it.
How many of Takahashi's friends will learn the secret in the end?

Constraints

  • 2 \leq N \leq 10^52N105
  • 1 \leq X \leq N1XN
  • 1 \leq A_i \leq N1AiN
  • A_i \neq iAi=i
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:
NNXXA_1A1A_2A2\cdotsA_NAN

Output

Print the answer.

Sample Input Copy

4 2
3 1 1 2

Sample Output Copy

3

HINT

Takahashi's secret will be learned by Friend 11, Friend 22, and Friend 33, as follows.

  • One day, Takahashi let Friend 22 learn the secret.
  • Friend 22 shares it with Friend 11.
  • Friend 11 shares it with Friend 33.

In the end, three of his friends learn the secret, so we print 33.

Source/Category