program test03_3
 integer N, K
 integer,allocatable :: H(:)
 integer :: saijyaku(1)=0
 integer :: saikyou(1)=0
 integer(8) :: kougeki=0
 integer i

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

 read *, H

 kougeki=sum(H)

 do i=1,K
  if ( kougeki == 0 ) exit
  saikyou=maxloc(H,H>=0)
  kougeki=kougeki-H(saikyou(1))
  H(saikyou(1))=-1
 end do

 print '(i0)',kougeki

endprogram test03_3
