An intelligence agency employs n spies. Each spy shadows exactly one other spy. This shadowing assignment is fixed: spy k shadows spy ak (with ak=k).
The agency wants to assign as many spies as possible to a secret operation. However, every spy taking part in the operation must be shadowed by at least one spy that does not take part in it. (The shadowing assignment never changes.)
Write a program that:
The first line contains the number of spies n (2≤n≤106). The spies are numbered from 1 to n. Each of the next n lines describes whom a spy shadows: the (k+1)-th line contains a single integer ak, meaning that spy k shadows spy ak (1≤k≤n, 1≤ak≤n, ak=k).
Print a single integer: the maximum number of spies that can be assigned to the secret operation.
