integer :: n,k
integer,allocatable :: p(:)
integer :: i,j, buffer


read*,n,k
allocate( p(n) )
read*,p

do i = 1,n-1
do j = i+1,n
  if( p(i)>p(j) )then
    buffer = p(i)
    p(i) = p(j)
    p(j) = buffer
  end if
end do
end do

print*,sum(p(1:k))
end program

    