program main
	implicit none
	integer :: N, i, S
	integer, allocatable :: a(:)
	
	read(*, *) N
	allocate(a(1:N))
	read(*, *) a
	
	S = 0
	do i = 1, N
		if(i == a(a(i)) .AND. i < a(i)) then
			S = S + 1
		end if
	end do
	
	write(*, *) S
end program main