local mma = math.max
local t = {}
local tnormal = {}
local tlim = {}
local n, k = io.read("*n", "*n", "*l")
local digmax = 40
local kval = {}
for i = 1, digmax do kval[i] = 0 end
local kdig = 0
do
  local tk = k
  while 0 < tk do
    kdig = kdig + 1
    kval[kdig] = tk % 2
    tk = tk // 2
  end
  if k == 0 then kdig = 1 end
end
for i = 1, digmax do
  t[i], tnormal[i], tlim[i] = 0, 0, 0
end
local str = io.read()
local adigmax = 1
for v in str:gmatch("(%d+)") do
  local a = tonumber(v)
  local adig = 1
  for i = 1, digmax do
    if 0 < a then adig = i end
    t[i] = t[i] + (a % 2)
    a = a // 2
  end
  adigmax = mma(adigmax, adig)
end
digmax = mma(kdig, adigmax)
local mul = 1
for i = 2, digmax do
  mul = mul * 2
end
if kval[digmax] == 0 then
  tlim[digmax] = t[digmax] * mul
  tnormal[digmax] = 0
else
  tlim[digmax] = (n - t[digmax]) * mul
  tnormal[digmax] = t[digmax] * mul
end
mul = mul // 2
for i = digmax - 1, 1, -1 do
  if kval[i] == 0 then
    tlim[i] = tlim[i + 1] + t[i] * mul
    tnormal[i] = tnormal[i + 1] + mma(n - t[i], t[i]) * mul
  else
    tlim[i] = tlim[i + 1] + (n - t[i]) * mul
    tnormal[i] = mma(tlim[i + 1] + t[i] * mul,
                     tnormal[i + 1] + mma(n - t[i], t[i]) * mul)
  end
  mul = mul // 2
end
print(mma(tlim[1], tnormal[1]))
