program kudamono
read*,n,k
call fruit(n,k)

end program

subroutine fruit(n,k)
integer::p(1:n)
integer::a(1:n)

read*,(p(j),j=1,n)
do i=n,2,-1
 do j=1,i-1
  if (p(j)>p(j+1)) then
   ntemp=p(j)
   p(j)=p(j+1)
   p(j+1)=ntemp
  end if
 end do
end do 
isum=0
do i=1,k
isum=isum+p(i)
end do
print*,isum
end subroutine fruit