import Control.Monad
import Data.Bits
import Data.Word
main = do
  [n,k] <- map read . words <$> getLine :: IO [Word64]
  abs <- replicateM (fromIntegral n) $ map read . words <$> getLine
  print $ maximum 
    $ sum [b| [a,b] <- abs, k.|.a == k]
    : [sum [b| [a,b] <- abs, a<=r || p<=a && a<=r+p] |
        let (m:_) = [m| m <- [1..], 2^m > k],
        i <- [m-1,m-2..0],
        testBit k i,
        let r = 2^i - 1
            p = clearBit k i .&. complement r]