  Program Main

    Implicit None

    Integer, Allocatable :: H(:) 
    Integer(8)           :: i,j,N,K,s,Hmax

    N = 0 ; K = 0 ; s = 0 ; Hmax = 0
    Read(*,*) N,K
    Allocate (H(N)); H(:) = 0.0d0 
    Read(*,*)(H(i),i=1,N)
    Hmax = Maxval(H(:))

    If (K < N) then
       If (K /= 0)then
       Loop:Do
          Check:Do j = 1,N
                   If (H(j) == Hmax) then
                      H(j) = 0
                      Hmax = Maxval(H(:))
                      s  = s + 1
                      If (s == k) Exit Loop
                   Endif
                Enddo Check
            Enddo Loop
       Endif

       s = 0
       Do i = 1,N
          s = s + H(i)
       Enddo
    Endif


    Write(*,"(I0)") s
    Deallocate(H)

  End Program
