program prob3
    implicit none
    integer :: N, i, ans
    integer, allocatable :: a(:)
    read(*,*) N
    allocate(a(N))
    read(*,*) a
    ans = 0
    do i = 1, N
        if(a(a(i)) == i)then
            ans = ans + 1
        end if
    end do
    ans = ans / 2
    write(*,*) ans



    deallocate(a)

    stop
contains
end program prob3