N = int(input()) P = [0]+list(map(int,input().split())) Col = [-1]*(N+1) cnt = 0 for i in range(1,N+1): if Col[i]>=0:continue cur = i while Col[cur]<0: Col[cur] = cnt cur = P[cur] cnt += 1 C = {} for i in range(1,N+1): if Col[i]>=0: C[Col[i]] = C.get(Col[i],0)+1 ans = 0 for c in C: ans += C[c]-1 print(ans)