--url : https://devforum.roblox.com/t/commonly-used-tree-data-structures-in-lua/265673/5

--[[
	vEB (van Emde Boas Trees)
	
	This is slow because it recurses and calls functions. Because of this, it is recommended to use a Red-Black Binary Search Tree instead.
	
    u defines the desired upper bound, each node has u^0.5 children.
    You want u to be as close as possible to the maximum Value.

    You can insert negative numbers as well but it is a bit inefficient so it is better to offset all of the numbers by a constant beforehand.
	
	Sources:
		https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-046j-design-and-analysis-of-algorithms-spring-2015/lecture-notes/MIT6_046JS15_lec04.pdf
		https://www.youtube.com/watch?v=hmReJCupbNU
		https://github.com/erikwaing/VEBTree
		
	Complexity:
		Min: O(1)
		Max: O(1)
		Member: O(lglg(u))
		Upper Bound: O(lglg(u))
		Lower Bound: O(lglg(u))
		Insertion: O(lglg(u))
		Deletion: O(lglg(u))

	Example Usage:
		local v = require(this).New(15)

		v:Insert(1)
		v:Insert(3)
		v:Insert(4)
		v:Insert(5)
		v:Insert(7)
		v:Insert(8)
		v:Insert(10)
		v:Insert(0)
		v:Insert(12)
		v:Insert(14)
		
		print(v:UpperBound(13))
		
		-- iterating
		local i = v.Min
		while i do
			print(i)
			i = v:Successor(i)
		end
	
--]]

-- Constants

-- efficiency variables
local error=error
local floor=math.floor

-- local variables

local function newveb(u)
	local self={
		u,-- u
		false,-- min
		false,-- max
		false,
		false,
		floor(u^.5),
	}
	
	if u>2 then
		local clusters={}
		for i=1,self[6]+1 do
			clusters[i]=false
		end
		
		self[4]=clusters-- clusters
		--self[5] = nil -- summary
	end
	
	return self
end

local function high(self,x)
	return floor(x/self[6])+1
end

local function low(self,x)
	return x%self[6]+1
end

local function index(self,h,l)
	return(h-1)*self[6]+l-1
end

local function member(self,x)
	-- returns whether x is a member of the vEB
	if x==self[2]or x==self[3]then
		-- found x as the min or max
		return true
	elseif self[1]<=2 then
		-- has not found x in the "leaf"
		return
	else
		local cluster=self[4][high(self,x)]
		if cluster then
			-- look for x in the cluster
			return member(cluster,low(self,x))
		end
	end
end

local function successor(self,x)
	local m=self[2]
	if self[1]<=2 then
		if x==0 and self[3]==1 then
			return 1
		end
	elseif m and x<m then
		-- x is less than everything in the tree, return the minimum
		return m
	else
		local h=high(self,x)
		local l=low(self,x)
		m=self[4]
		local cluster=m[h]
		local n=cluster and cluster[3]
		
		if n and l<n then
			return index(self,h,successor(cluster,l))
		else
			n=self[5]
			if n then
				n=successor(n,h)
				if n then
					local cluster2=m[n]
					if cluster2 then
						return index(self,n,cluster2[2])
					end
				end
			end
		end
	end
end

local function predecessor(self,x)
	local n=self[2]
	local m=self[3]
	if self[1]<=2 then
		if x==1 and n==0 then
			return 0
		end
	elseif m and x>m then
		return m
	else
		local h=high(self,x)
		local l=low(self,x)
		m=self[4]
		local cluster=m[h]
		local minlow=cluster and cluster[2]
		
		if minlow and l>minlow then
			return index(self,h,predecessor(cluster,l)or 0)
		else
			local predcluster=self[5]
			if predcluster then
				predcluster=predecessor(predcluster,h)
			end
			if predcluster then
				m=m[predcluster]
				return index(self,predcluster,(m and m[3])or 0)
			elseif n and x>n then
				return n
			end
		end
	end
end

local function insert(self,x)
	local m=self[2]
	if m then
		if x<m then
			-- swap x and min if x is less than min to *actually* insert min instead of x
			self[2]=x
			x=m
		end
		
		m=self[1]
		if m>2 then
			m=high(self,m)
			local h=high(self,x)
			local cluster=self[4][h]
			local summary=self[5]
			
			if not cluster then
				-- if the cluster doesn't exist then create it (save space by not having it exist) and set its bound to sqrt of u
				cluster=newveb(m)
				self[4][h]=cluster
			end
			if not summary then
				summary=newveb(m)
				self[5]=summary
			end
			if cluster[2]then
				insert(cluster,low(self,x))
			else
				insert(summary,h)
				local x=low(self,x)
				cluster[2]=x
				cluster[3]=x
			end
		end
		if x>self[3]then
			self[3]=x
		end
	else
		self[2]=x
		self[3]=x
	end
end

local function delete(self,x)
	local h
	local m=self[4]
	local p=self[5]
	
	if x==self[2]then
		h=p
		h=h and h[2]
		if not h then
			self[2]=nil
			self[3]=nil
			return
		end
		
		x=index(self,h,m[h][2])
		self[2]=x
	end
	
	local o=high(self,x)
	local n=m[o]
	delete(n,low(self,x))
	if not n[2]then
		delete(p,o)
		m[o]=false--nil -- delete it if its not being used
	end
	if x==self[3]then
		local h=p[3]
		self[3]=h and index(self,h,m[h][3])or self[2]
	end
end

local function vinsert(self,x)
	insert(self,x)
	self.min=self[2]
	self.max=self[3]
	self.Size=self.Size+1
	
	return self
end

local function vdelete(self,x)
	delete(self,x)
	self.min=self[2]
	self.max=self[3]
	self.Size=self.Size-1
	
	return self
end

local function vupperbound(self,x)
	return predecessor(self,x+1)
end

local function vlowerbound(self,x)
	return successor(self,x-1)
end

local function vclear(self)
	self[2]=false
	self[3]=false
	local a=self[4]
	if a then
		for i=1,#a do
			a[i]=false
		end
	end
	self[5]=false
	
	return self
end

local function vempty(self)
	return not self[1]
end

local veb={
	insert=vinsert,
	delete=vdelete,
	member=member,
	upperbound=vupperbound,
	lowerbound=vlowerbound,
	successor=successor,
	predecessor=predecessor,
	clear=vclear,
	empty=vempty,
}

function veb.new(u)
	if u<0 then
		error('Upper bound cannot be less than 0',2)
	end
	
	local self=newveb(u)
	
	self.Size=0
	self.max=false
	self.min=false
	self.u=u
	
	self.insert=vinsert
	self.delete=vdelete
	self.member=member
	self.upperbound=vupperbound
	self.lowerbound=vlowerbound
	self.clear=vclear
	self.empty=vempty
	self.successor=successor
	self.predecessor=predecessor
	
	return self
end

---------

local n,m=io.read("n","n")
local a=veb.new(n)
for i=1,n do
    local input=io.read("n")
    a:insert(input)
end

for i=1,m do
    x=a.max
    a:delete(x)
    x=x//2
    a:insert(x)
end

local total=0
for i=1,n do
    local x=a.max
    a:delete(x)
    total=total+x
end
print(total)