f n ('2':s) i =0:(f n s i)
f 1 _ i       =[i]
f n s i       =if s!!0==s!!1 then(f(n-1)(tail s)(i+1))else(i:(f(n-1)(tail s)1))
g n k t s i a |n<2       =max i a
              |otherwise =g (n-2) k (drop 2 t) (drop 2 s) (max i a) (a-(sum(take 2 s))+(sum(take 2 t)))
main=do
 [n,k]<-map read.words<$>getLine
 s<-(\x->f n x 1).(\x->if x!!0=='1' then x else ('2':x))<$>getLine
 print(g ((length s)-2*k) (2*k+1) (drop(2*k+1)s) s 0 (sum(take(2*k+1)s)))