module priority_queue
    use,intrinsic :: iso_fortran_env
    type heap
        integer(int64):: i
        integer(int64), allocatable:: v(:)
    end type
    private
    public:: heap
    public:: init_heap
    public:: append_heap
    public:: pop_heap

contains
    subroutine init_heap(h)
        type(heap):: h
        h%i=0
        allocate(h%v(1))
    end subroutine

    subroutine append_heap(h,x)
        type(heap):: h
        integer(int64):: x
        if (h%i+1 >= size(h%v)) call add(h)
        h%i=h%i+1
        h%v(h%i) = x
        call heap_up(h,h%i)
    end subroutine

    function pop_heap(h) result(v)
        type(heap):: h
        integer(int64):: v
        v=h%v(1)
        h%v(1) = h%v(h%i)
        h%i=h%i-1
        call heap_down(h,1_8)
    end function

    subroutine add(h)
        type(heap):: h
        integer(int64):: l
        integer(int64), allocatable:: tmp(:)
        l = size(h%v)
        allocate(tmp(l))
        tmp(:) = h%v(:)
        deallocate(h%v)
        allocate(h%v(l*2))
        h%v(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine

    recursive subroutine heap_up(h,self)
        type(heap):: h
        integer(int64):: self
        if (self == 1) return

        if (h%v(self) > h%v(self/2))then
            call swap(h%v(self),h%v(self/2))
            call heap_up(h,self/2)
        end if
    end subroutine

    recursive subroutine heap_down(h,self)
        type(heap):: h
        integer(int64):: self,c1,c2

        c1 = self*2
        c2 = c1+1
        if (c2 <= h%i) then
            if (h%v(c1) >= h%v(c2)) then
                if (h%v(c1) > h%v(self)) then
                    call swap(h%v(c1),h%v(self))
                    call heap_down(h,c1)
                end if
            else
                if (h%v(c2) > h%v(self)) then
                    call swap(h%v(c2),h%v(self))
                    call heap_down(h,c2)
                end if
            end if
        else if (c1 <= h%i) then
            if (h%v(c1) >= h%v(self)) then
                call swap(h%v(c1),h%v(self))
                call heap_down(h,c1)
            end if
        else
            return
        end if
    end subroutine

    subroutine swap(x,y)
        integer(int64):: x,y,t
        t=x; x=y; y=t
    end subroutine
end module

program abc141
    use,intrinsic :: iso_fortran_env
    use priority_queue
    implicit none
    integer(int64):: n,m,i,ans
    integer(int64), allocatable:: ia(:)
    type(heap):: a

    call init_heap(a)
    read*, n,m
    allocate(ia(n))
    read*, ia(:)
    do i=1,n
        call append_heap(a,ia(i))
    end do

    do i=1,m
        call append_heap(a,pop_heap(a)/2)
    end do
    
    ans=0
    do i=1,n
        ans=ans+pop_heap(a)
    end do
    print'(i0)', ans
    
end program abc141