module subprogs
    implicit none
    contains
    subroutine quicksort2(n,x)
      !  implicit none
        integer,intent(in)::n
        integer,intent(inout)::x(1:n)
        integer,allocatable::ix(:),iw(:) 
        !
        ! Original
        ! http://d.hatena.ne.jp/fortran66/20120415/1334423664
        !
        integer :: i, j, kk0, kk1, k0, k1, ix0, ix1, l, nx
        double precision :: tmp
      
        allocate(ix(n),iw(n))
        ix=0
        iw=0
      
        if (n < 2) return
        ix(1) = 1
        ix(2) = n 
        nx = 2
        do while(nx.ne.0)
           l = 0
           do j = 1, nx - 1, 2
              kk0 = ix(j) 
              kk1 = ix(j + 1) 
              k0 = kk0 + 1
              k1 = kk1
              do while(k0 <= k1)
                 do ix0 = k0, k1              ! L
                    if (x(ix0) > x(kk0)) exit 
                 end do
                 do ix1 = k1, k0, -1          ! R
                    if (x(ix1) < x(kk0)) exit 
                 end do
                 if (ix0 >= ix1) exit
                 tmp = x(ix0)                 !swap
                 x(ix0) = x(ix1)
                 x(ix1) = tmp
                 k0 = ix0 + 1
                 k1 = ix1 - 1
              end do
              tmp = x(kk0)                   ! CSHIFT(x(kk0:ix1), 1)
              do i = kk0, ix1 - 1
                 x(i) = x(i + 1)
              end do
              x(ix1) = tmp
              if (kk0 < ix1 - 1) then         ! L
                 l = l + 1
                 iw(l) = kk0 
                 l = l + 1
                 iw(l) = ix1 - 1
              end if
              if (kk1 > ix0) then             ! R
                 l = l + 1
                 iw(l) = ix0
                 l = l + 1
                 iw(l) = kk1
              end if
           end do
           nx = l
           ix(1:nx) = iw(1:nx)
        end do
      
        return
      end subroutine quicksort2
  end module subprogs

program fennec_monster
use subprogs
implicit none
integer :: n,k,i
integer(8) :: Dsum 
integer,allocatable :: h(:)
Dsum = 0
read(*,*) n,k
allocate(h(n))
read(*,*) h(:)
call quicksort2(n,h)
!print*,h(:)
if (n -k > 0)then

    do i = 1 ,n-k
        Dsum = Dsum + h(i)
    end do
end if

    write(*,*) Dsum
end program fennec_monster