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
  sizeOf x = finiteBitSize x - countLeadingZeros x
  sizeK = sizeOf k

  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.foldl' (\acc t -> acc * 2 + t) 0 $ V.unfoldrN (sizeOf y) (\i -> Just . flip (,) (i-1) $ (if testBit y i then fst else snd) $ fbitMap V.! i) (sizeOf y - 1)

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

  fbitMap = V.unfoldrN sizeK (\n -> Just . flip (,) (n+1) $ let t = fbit n True in (t, V.length xs - t)) 0

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

