program ABC171_B
  integer::N,K
  integer,allocatable::P(:)
  read(*,*)N,K
  allocate(P(N))
  read(*,*)P
  do i=1,N-1
     do j=i+1,N
        if(P(i)>P(j)) then
           L=P(i)
           P(i)=P(j)
           P(j)=L
        end if
     end do
  end do
  write(*,*)sum(P(1:K))
end program ABC171_B