import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bits (testBit)
import Data.List (mapAccumL)
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  [n, k] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    fromIntToBools :: Int -> [Bool]
    fromIntToBools = flip map is . testBit
      where
        is = [39, 38..0] :: [Int]
    k' = fromIntToBools k :: [Bool]
  as <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    maxF = snd . mapAccumL step (Just k') . counts $ as :: [Int]
      where
        step :: Maybe [Bool] -> Int -> (Maybe [Bool], Int)
        step (Just (False : bs')) c             = (Just bs', c)
        step (Just (_ : bs'))     c | 2 * c < n = (Just bs', n - c)
                                    | otherwise = (Nothing, c)
        step Nothing              c             = (Nothing, max c (n - c))
  print . fromDigitsToInt $ maxF

fromDigitsToInt :: [Int] -> Int
fromDigitsToInt = foldl step 0
  where
    step :: Int -> Int -> Int
    step ds d = 2 * ds + d
{-# INLINE fromDigitsToInt #-}

counts :: [Int] -> [Int]
counts = VU.toList . VU.accum (+) (VU.replicate 40 0) . map (flip (,) 1 . (39 -)) . concatMap (flip filter [0..39] . testBit)
{-# INLINE counts #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
