{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import System.IO.Unsafe
import Debug.Trace

solve :: Int -> Int -> B.ByteString -> Int
solve n k ss = maximum
  [ accums
    VU.! ((i + k') `min` (gn - 1))
    -    (if i - k' - 1 >= 0 then accums VU.! (i - k' - 1) else 0)
  | i <- [0 .. gn - 1]
  , let k' =
          if is0AtNthGroup i then ((k - 1) `div` 2) * 2 + 1 else (k `div` 2) * 2
  ]
 where
  (_, istream, gn) = fix
    ( \f (bs, acc, g) -> if B.length bs == 0
      then (bs, acc, g)
      else if B.last bs == '0'
        then
          let (other, zeros) = B.spanEnd (== '0') bs
          in  f (other, B.length zeros : acc, g + 1)
        else
          let (other, ones) = B.spanEnd (== '1') bs
          in  f (other, B.length ones : acc, g + 1)
    )
    (ss, [], 0)

  accums :: VU.Vector Int
  accums = unsafePerformIO $ VU.freeze $ (\(x, _, _) -> x) $ foldl'
    ( \(acc, i, prev) k ->
      let cur = prev + k
      in  cur
            `seq` ( unsafePerformIO $ (VM.write acc i cur >> return acc)
                  , i + 1
                  , cur
                  )
    )
    (unsafePerformIO $ VM.new gn, 0, 0)
    istream

  is0AtNthGroup n = if B.head ss == '0' then even n else odd n

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nk <- V.unfoldrN 2 readInt <$> B.getLine
  ss <- B.getLine
  print $ solve (nk V.! 0) (nk V.! 1) ss
