program DBS
 implicit none
 integer::N=0,K=0,s=0,i,ishota,ishotb,p=0,q=0
 integer,allocatable::a(:)
 read(*,*)N,K
 allocate(a(N))
 read(*,*)(a(i),i=1,N)
 do ishota=1,N
  do ishotb=1,N-1
   if(a(ishotb)>a(ishotb+1))then
    p=a(ishotb)
    q=a(ishotb+1)
    a(ishotb)=q
    a(ishotb+1)=p
   end if
  end do
 end do
 s=sum(a(1:K))
 print'(i0)',s
 deallocate(a)
end program DBS