program answer2
 implicit none
 
 integer :: i, j, N, K, m
 integer, allocatable :: p(:)
 
 read(*,*) N, K
 allocate(p(N))
 read(*,*) p
 
 do j =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
 
 m=0
 do i =1, K
   m= m+p(i)
 end do
 stop
end program answer2
 