program sample
implicit none

integer(8) :: N, K, i, sum
integer(8), allocatable:: p(:)

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

if(N > 1)then
do i = 1, N-1
if(p(i) >= p(i+1))then
p(i)=p(i+1)
p(i+1)=p(i)
endif
end do

sum = 0
do i = 1, K
sum = sum + p(i)
end do

write(*,*) sum
end if

if(N == 1)then
sum = p(1)
write(*,*) sum
end if

stop


end program sample