import Data.Int
import Data.Bits
toi True = 1
toi False = 0
btoi xs = sum $ zipWith (*) xs $ map (2^) [0..]
-- f :: Int64 -> Int64 -> [Int64] -> Int64
f nn xx yys = go xx 41 urettat
  where
    tatteru = map (\a -> sum $ map (\y -> toi $ testBit y a) yys) [0..41]
    zakos = map (\a -> max a (nn - a)) tatteru
    urettat = reverse tatteru
    zako n = btoi $ take n zakos
    go :: Int64 -> Int -> [Int64] -> Int64
    go k n xs
      | n < 0 = 0
      | k < 2^n = 2^n*(head xs) + go k (n-1) (tail xs)
      | k >= 2^n = max (2^n*(head xs) + zako n) (2^n*(nn-head xs) + go (k-2^n) (n-1) (tail xs))

main = do
  [n,k] <- map (read::String->Int64) . words <$> getLine
  xs <- map (read::String->Int64) . words <$> getLine
  print $ f n k xs
