program sample
implicit none

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

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

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


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

write(*,*) sum


deallocate(p)
stop

end program sample