
import Data.Bits (xor, shiftL, (.&.))
import Data.Array (listArray, (!))
import Data.Maybe (fromJust)

f as x = sum $ fmap (xor x) as

maxdigit = 50

main = do
  n:k:_ <- map read . words <$> getLine :: IO [Int]
  as <- map read . words <$> getLine :: IO [Int]
  let result = solv k n as
  print . fromJust $ max (result ! 0) (result ! 1)

dp f s n = result ! n where
  result = listArray (s,n) $ map nth [s..]
  nth i = f result i

solv k num as = dp f 0 maxdigit where
  f _ 0   = listArray (0,1) [Just 0, Nothing]
  f tab n =
    let mask  = shiftL 1 (maxdigit - n)

        d0    = tab ! (n-1) ! 0
        d1    = tab ! (n-1) ! 1

        cost0 = sum $ map (.&.mask) as
        cost1 = mask * num - cost0

        stos  = (+(max cost0 cost1)) <$> d1
        etos  = if k .&. mask > 0 then (+cost0) <$> d0 else Nothing
        etoe  = if k .&. mask > 0 then (+cost1) <$> d0 else (+cost0) <$> d0
    in
      listArray (0,1) [etoe, max stos etos]
