{-# LANGUAGE TupleSections #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Control.Monad.State (State, evalState, gets, modify)
import Data.Map.Strict (Map, lookup, insert, empty)
import Data.Bits
import Debug.Trace 
import qualified Data.Set as S

main :: IO ()
main = readLine >>= main'
    where
        main' [n, k] = readLine >>= print . solve n k 

solve :: Int -> Int -> [Int] -> Int
solve n k as = foldl' ff 0 [40,39..0] -- cs
    where
        bsvs = V.fromList $ scanl (+) 0 as
        bs = [bsvs V.! i - bsvs V.! j | i <- [1..n], j <- [0..(i - 1)]]--, i - j + k - 1 <= n]
        cs = filter (\(_, s) -> S.size s >= k) $ map count [40,39..0]
        count e = (v,) . S.fromList $ filter (\b -> b .&. v /= 0) bs
            where
                v = shiftL 1 e

        ff acc e 
            | length xs >= k = next
            | otherwise = acc
            where
                v = shiftL 1 e
                next = acc + v
                xs = filter (\b -> b .&. next == next) bs 

                {-
        ff (acc, ps) (v, s)
            | S.size t >= k = (acc + v, t)
            | otherwise = (acc, ps)
            where
                t = S.filter (flip S.member ps) s

        dbs = [(i - j, bsvs V.! i - bsvs V.! j) | i <- [1..n], j <- [0..(i - 1)]]
        (smalls, bigs) = partition (\(x, _) -> x <= n - k + 1) dbs
        res1 = maximum $ map snd smalls

        calc recf ((x : xs), c)
            | c == 0 = return $ complement 0
            | otherwise = max <$> recf (xs, c) <*> ((x .&.) <$> recf (xs, c - 1))
        calc _ (_, c)
            | c > 0 = return 0
            | otherwise = return $ complement 0
-}

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

type Memoizer a b = a -> State (Map a b) b

run :: (Ord a) => (Memoizer a b -> Memoizer a b) -> a -> b
run f = flip evalState empty . memoizeFix f

memoizeFix :: (Ord a) => (Memoizer a b -> Memoizer a b) -> Memoizer a b
memoizeFix f x = gets (Data.Map.Strict.lookup x) >>= maybe (f (memoizeFix f) x >>= ((<$) <*> (modify . Data.Map.Strict.insert x))) return