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.filter (\c -> c <= k)
    $ V.map candidate
    $ V.filter (\i -> testBit k i)
    $ V.enumFromN 0 (sizeOf k + 1)
 where
  sizeOf x = finiteBitSize x - countLeadingZeros x

  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)

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

  trailing1Bit n = 2 ^ n - 1

  f n = V.sum $ V.map (`xor` n) xs

  candidate n =
    let top    = k .&. foldl' (.|.) 0 (map bit [n .. sizeOf k])
        buttom = maxF .&. foldl' (.|.) 0 (map bit [0 .. (n - 1)])
    in  top + buttom

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
