program juice
	implicit none
    integer :: n, k, i, m, j
    integer,allocatable :: p(:)
    
    read(*,*) n, k
    allocate(p(n))
    
    read(*,*) p
    
    do i = n, 2, -1
    	do j = 1, i-1
        	if ( p(j)>=p(j+1) ) then
            	m = p(j+1)
                p(j+1) = p(j)
                p(j) = m
            end if
        end do
    end do
    
    write(*,*) sum(p(1:k))
    
    stop
end program juice