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