N=int(input()) A=list(map(int,input().split())) B=[0]*N D=[] ANS=0 for n in range(N): if B[n]==0:#未出発なら s=n D.append(s) while True: if B[A[s]-1]==0: s=A[s]-1 D.append(s) B[s]=1 elif B[A[s]-1]==1: ANS+=1 B[s]=2 if len(D)==1: break else: D.pop() s=D[-1] else: B[s]=2 if len(D)==1: break else: D.pop() s=D[-1] print(ANS)