implicit none
integer :: i,n,ans
integer,allocatable,dimension(:) :: a
read*,n
allocate(a(n))
ans = 0
read(*,*)(a(i),i=1,n)
do i=1,n
  if(a(a(i))==i)then
    ans = ans + 1
  endif
enddo
write(*,'(I0)')ans/2
end