module priority_queue
    implicit none
    private
    integer:: last
    integer(8), allocatable:: pq(:)
    public:: pq_init, pq_push, pq_pop
contains
subroutine pq_init(n)
    integer:: n
    allocate(pq(n))
    last = 0
end subroutine

subroutine pq_push(x)
    integer(8)::x
    integer:: ins, p
    last = last + 1
    
    ins = last
    p = last / 2
    do while(p >= 1)
        if(pq(p) >= x) exit
        pq(ins) = pq(p)
        ins = p
        p = ins / 2
    end do

    pq(ins) = x
    ! print*, pq(1:last)
end subroutine

function pq_pop() result(ret)
    integer(8):: ret, last_value
    integer:: ins, c1, c2
    ret = pq(1)
    last_value = pq(last)
    last = last - 1
    ins = 1
    c1 = ins*2
    c2 = c1 + 1

    do while(c1 <= last)
        if(max(pq(c1),pq(c2)) <= last_value) exit
        if(pq(c2) > pq(c1))c1 = c2
        pq(ins) = pq(c1)
        ins = c1
        c1 = ins*2
        c2 = c1 + 1 
    end do
    pq(ins) = last_value

    ! print*, c1, last_value
    ! print*, pq(1:last)
end function
    
end module

program main
    use priority_queue
    implicit none
    integer:: n,m, i,j,k
    integer(8):: max_, ans
    integer(8), allocatable:: a(:)

    read*, n, m
    allocate(a(n))
    read*, a(1:n)
    call pq_init(n)

    do i = 1, n
        call pq_push(a(i))
    end do

    do while(m > 0)
        max_ = pq_pop()
        max_ = max_ / 2
        call pq_push(max_)
        m = m - 1
    end do
    ans = 0
    do i = 1, n
        ans = ans + pq_pop()
    end do

    print*, ans    
end program