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