import sys
input = sys.stdin.buffer.readline
from math import log

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]

for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break

s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]
for i in range(n):
    s_table[i][0] = table[i][0]

import heapq
hq = []
heapq.heapify(hq)
h_push = heapq.heappush
h_pop = heapq.heappop

for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break


ans = sum(a)

for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
    
print(ans)

 import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline from math import log n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m a = list(map(int,input().split())) a list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split a.sort() a.sort a sort [0]*(int(log(a[-1],2))+2) for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*(int(log(a[-1],2))+2) [0] 0 int(log(a[-1],2))+2 int(log(a[-1],2)) int log(a[-1],2) log a[-1] a -1 2 2 table = [[0]*(int(log(a[-1],2))+2) for i in range(n)] table [[0]*(int(log(a[-1],2))+2) for i in range(n)] for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break i range(n) range n for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break y range(int(log(a[-1],2))+2) range int(log(a[-1],2))+2 int(log(a[-1],2)) int log(a[-1],2) log a[-1] a -1 2 2 table[i][y] = a[i]//pow(2,y) table[i][y] [i] table i y a[i]//pow(2,y) a[i] a i pow(2,y) pow 2 y if a[i]//pow(2,y) == 0:
            break a[i]//pow(2,y) == 0 a[i]//pow(2,y) a[i] a i pow(2,y) pow 2 y 0 break [0]*(int(log(a[-1],2))+2) for i in range(n) for i in range(n) i range(n) range n for i in range(n) [0]*(int(log(a[-1],2))+2) [0] 0 int(log(a[-1],2))+2 int(log(a[-1],2)) int log(a[-1],2) log a[-1] a -1 2 2 s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)] s_table [[0]*(int(log(a[-1],2))+2) for i in range(n)] for i in range(n):
    s_table[i][0] = table[i][0] i range(n) range n s_table[i][0] = table[i][0] s_table[i][0] [i] s_table i 0 table[i][0] [i] table i 0 import heapq heapq hq = [] hq [] heapq.heapify(hq) heapq.heapify heapq heapify hq h_push = heapq.heappush h_push heapq.heappush heapq heappush h_pop = heapq.heappop h_pop heapq.heappop heapq heappop for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break i range(n) range n for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break y range(1,int(log(a[-1],2))+2) range 1 int(log(a[-1],2))+2 int(log(a[-1],2)) int log(a[-1],2) log a[-1] a -1 2 2 s_table[i][y] = table[i][y]-table[i][y-1] s_table[i][y] [i] s_table i y table[i][y]-table[i][y-1] table[i][y] [i] table i y table[i][y-1] [i] table i y-1 y 1 h_push(hq,table[i][y]-table[i][y-1]) h_push hq table[i][y]-table[i][y-1] table[i][y] [i] table i y table[i][y-1] [i] table i y-1 y 1 if table[i][y]-table[i][y-1] == -1:
            break table[i][y]-table[i][y-1] == -1 table[i][y]-table[i][y-1] table[i][y] [i] table i y table[i][y-1] [i] table i y-1 y 1 -1 break ans = sum(a) ans sum(a) sum a for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
     i range(m) range m if not hq:
        print(0)
        exit()
     not hq hq print(0) print 0 exit() exit ans += h_pop(hq) ans h_pop(hq) h_pop hq print(ans) print ans ans = sum(a) sum(a) ans hq = [] [] hq input = sys.stdin.buffer.readline sys.stdin.buffer.readline input n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m h_push = heapq.heappush heapq.heappush h_push table = [[0]*(int(log(a[-1],2))+2) for i in range(n)] [[0]*(int(log(a[-1],2))+2) for i in range(n)] table ans += h_pop(hq) h_pop(hq) ans s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)] [[0]*(int(log(a[-1],2))+2) for i in range(n)] s_table h_pop = heapq.heappop heapq.heappop h_pop a = list(map(int,input().split())) list(map(int,input().split())) a
import sys
input = sys.stdin.buffer.readline
from math import log

n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()

table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]

for i in range(n):
    for y in range(int(log(a[-1],2))+2):
        table[i][y] = a[i]//pow(2,y)
        if a[i]//pow(2,y) == 0:
            break

s_table = [[0]*(int(log(a[-1],2))+2) for i in range(n)]
for i in range(n):
    s_table[i][0] = table[i][0]

import heapq
hq = []
heapq.heapify(hq)
h_push = heapq.heappush
h_pop = heapq.heappop

for i in range(n):
    for y in range(1,int(log(a[-1],2))+2):
        s_table[i][y] = table[i][y]-table[i][y-1]
        h_push(hq,table[i][y]-table[i][y-1])
        if table[i][y]-table[i][y-1] == -1:
            break


ans = sum(a)

for i in range(m):
    if not hq:
        print(0)
        exit()
    ans += h_pop(hq)
    
print(ans)


