program test03_2
 integer N, K
 integer,allocatable :: H(:)
 integer :: saijyaku(1)=0
 integer(8) :: kougeki=0
 integer i
 logical m

 read *, N, K
 allocate(H(N))

 read *, H

!m=-1

 do i=1,N-K
  saijyaku=minloc(H,H>=0)
  kougeki=kougeki+H(saijyaku(1))
  H(saijyaku(1))=-1
 end do


 print '(i0)',kougeki

endprogram test03_2
