import qualified Data.ByteString.Char8 as B
import Data.List
import Data.Ord
import Data.Bits

main=do
    [n,k]<-map read.words<$>getLine::IO[Int]
    as<-unfoldr(B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    print $ sol k as

sol k as = sum $ unfoldr (f k) (2^40, ss)
    where
        ss = concatMap (scanl1 (+)) $ tails as

f k (bm,ss)
    | bm == 0 = Nothing
    | length ks >= k = Just(bm, (bm`div`2, ks))
    | otherwise = Just(0, (bm`div`2, ss))
    where
        ks = filter (\s-> s.&.bm /= 0) ss
