program answer
  implicit none
  integer :: i, N, count
  integer, allocatable :: a(:)
  read(*,*) N
  allocate(a(N))
  read(*,*) a

  count=0
  do i = 1, N
     if(a(a(i))==i) then
        count=count+1
     end if
  end do
  
  write(*,*) count/2
  deallocate(a)
  stop
 end program answer
