import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Bits
import Debug.Trace

main :: IO ()
main = readContents 2 >>= main'
    where
        main' [[n, k], as] = print $ solve n k as

solve :: Int -> Int -> [Int] -> Int
solve n k as = maximum $ map (\x -> sum $ map (xor x) as) res
    where
        res = filter (<= k) $ map edit [0..40]

        edit i = hv + lv
            where
                lv = l .&. lm
                hv = h .&. hm
                lm = complement $ shiftL (shiftR oneBits j) j
                hm = shiftL (shiftR oneBits i) i
                j = max 0 $ i - 1

        oneBits = complement zeroBits

        l = build $ map count es
        h = foldl' ff l es
            where
                ff acc e
                    | e .&. k == 0 && e .&. l > 0 = acc - e
                    | otherwise = acc

        build = foldl' ff 0 . zip es
            where
                ff acc (e, b)
                    | b = acc + e 
                    | otherwise = acc

        count e = br $ foldl' ff (0, 0) as
            where
                br (a, b) = a < b
                ff (a, b) x
                    | e .&. x > 0 = (a + 1, b)
                    | otherwise = (a, b + 1) 

        es = map (2 ^) [39, 38..0]


readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine