module subprogram
	implicit none
contains
	subroutine bubblesort(N,array)
    integer,intent(in)::N
    integer,intent(inout)::array(1:N)
    integer::i,j
    integer::t
    do i=1,N-1
       do j=i+1,N
          if(array(i) .gt. array(j))then
             t=array(i)
             array(i)=array(j)
             array(j)=t
          end if
       end do
    end do
    return
	end subroutine bubblesort
end module subprogram

program main
	use subprogram
	implicit none
	integer N, K
	integer, allocatable :: l(:)
	read(*, *) N, K
	allocate(l(1: N))
	read(*, *) l(1: N)
	call bubblesort(N,l)
	l(1:N) = l(N:1:-1)
	write(*, *) sum(l(1:K))
end program main