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 = memo ! (50, False)
  where
    doit (-1, _)  = sum(a)
    doit (b, ok) | ok || k .&. msb /= 0 = max (memo ! (b - 1, ok) + diff) (memo ! (b - 1, True))
                 | otherwise            =      memo ! (b - 1, ok)
      where
        msb  = 1 `shift` b
        diff = sum $ [if ai .&. msb /= 0 then -msb else msb | ai <- a]
    memo = listArray ((-1, False), (50, True)) [doit (b, ok) | b <- [-1..50], ok <- [False, True]]
