program friendly_rabbits
  implicit none
  integer :: n, a(0:100000), m, i
  a = 0
  read(*,*) n
  read(*,*) a(1:n)
  m = 0
  do i = 1, n
    if (i.eq.a(a(i))) then
      a(i) = 0
      a(a(i)) = 0
      m = m + 1
    end if
  end do
  write(*,'(i0)') m
  stop
end program friendly_rabbits