import Control.Monad
import Data.Array
import Data.Bits
import Data.List

main = do
    [n, k] <- fmap read <$> words <$> getLine
    a      <- fmap read <$> words <$> getLine
    putStrLn $ show $ solve n k a

solve :: Integer -> Integer -> [Integer] -> Integer
solve n k a = doit 50 + sum a
  where
    doit (-1)                           = 0
    doit bit | k .&. 1 `shift` bit /= 0 = max (doit (bit - 1) + diff !! bit) $ sum $ take bit diff
             | otherwise                =      doit (bit - 1)
    diff = [max 0 $ sum $ [if ai .&. msb /= 0 then -msb else msb | ai <- a] | msb <- map (shift 1) [0..50]]
