import Control.Arrow (second)
import Data.Bits
import Data.List
import qualified Data.Vector.Unboxed as V
import qualified Data.ByteString.Char8 as B

solve :: Int -> V.Vector Int -> Int
solve k xs = V.maximum $ V.map f $ V.unfoldrN (k - solution + 1) (\b -> Just (b, b + 1)) solution where
  sizeK = go 0 k where
    go i acc
      | acc /= 0 = go (i+1) (shiftR acc 1)
      | otherwise = i

  minority :: Int -> V.Vector Int -> Int
  minority i = (\(count0, count1) -> if count0 <= count1 then 0 else 1)
              . V.foldl' (\(count0,count1) b -> if testBit b i then (count0, count1 + 1) else (count0 + 1, count1)) (0,0)

  idealMax :: Int
  idealMax = V.foldl' (\acc m -> acc * 2 + m) 0 $ V.unfoldrN sizeK (\i -> if i < 0 then Nothing else Just (minority i xs, i-1)) (sizeK - 1)

  solution :: Int
  solution = idealMax .&. k

  f :: Int -> Int
  f y = V.sum $ V.map (`xor` y) xs

  fbit :: Int -> Bool -> Int
  fbit i b = V.length $ V.filter id $ V.map ((`xor` b) . testBit i) xs

main = do
  nk <- V.unfoldrN 2 (fmap (second B.tail) . B.readInt) <$> B.getLine
  xs <- V.unfoldrN (nk V.! 0) (fmap (second B.tail) . B.readInt) <$> B.getLine
  print $ solve (nk V.! 1) xs

