module Main where
    import Debug.Trace
    import Data.List
    import qualified Data.Sequence as S
    import qualified Data.ByteString.Char8 as B
    import Data.Int
    import Data.Char
    import Data.Array
    import Data.Maybe
    import qualified Data.Map as M
    import Data.Ord
    import Data.Functor
    import Control.Applicative
    import Control.Monad
    
    solve :: Int -> Int -> [Int] -> Int
    solve n k wl = iter 0 (div (n * maximum wl) k +1) where
        iter failed successful
            | failed +1 == successful = successful
            | loadable p k wl = iter failed p
            | otherwise       = iter p successful where
                p = div (failed+successful) 2 

    loadable :: Int -> Int -> [Int] -> Bool
    loadable p k = iter 1 0 where -- 1st arg : number of tracks, 2nd arg : loaded weight 
        iter t _ [] = t <= k
        iter t l (w:ws)
            | t > k = False
            | w > p = False
            | lw <= p = iter t lw ws
            | otherwise = iter (t+1) w ws where
                lw = l+w

    readIntLn:: IO Int
    readIntLn = (fst . fromJust . B.readInt) <$> B.getLine

    readIntList:: IO [Int]
    readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
       
    readLines :: Int -> IO [Int]
    readLines n = replicateM n readIntLn
                
    main :: IO() 
    main = do
        [n, k] <- readIntList :: IO [Int]
        wl <- readLines n
        print $ solve n k wl

    
