program b171

implicit none
integer :: n, k, z, m, i, j
integer, allocatable :: p(:)

read *, n, k

allocate(p(1:n))

read *, p(:)

do i = 1, n
 do j = 1, n
  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

z = 0

do i = 1, k
 z = z + p(i)
end do

print *, z

end program b171