{-# LANGUAGE BangPatterns #-}

import           Control.Applicative
import           Control.Monad
import           Debug.Trace

split :: Int -> [Int] -> ([Int], [Int])
split p ws = go 0 [] ws
  where
    go _ !as [] = (reverse as, [])
    go !sumw !as (b:bs)
        | sumw + b > p = (reverse as, b : bs)
        | otherwise = go (sumw + b) (b : as) bs

allocate :: Int -> [Int] -> [[Int]]
allocate _ [] = []
allocate p ws
    | null r = [l]
    | otherwise = l : allocate p r
  where
    (l, r) = split p ws

solve :: Int   -- trucks
      -> [Int] -- weights
      -> Int   -- answer
solve k ws =
    let (l, r) = foldr (\w (a, b) -> (max w a, w + b)) (0, 0) ws
     in go l r
  where
    go :: Int -> Int -> Int
    go !l !r
        | l > r = l
        | t <= k = go l (m - 1)
        | otherwise = go (m + 1) r
      where
        m = (l + r) `div` 2
        t = length (allocate m ws)

main :: IO ()
main = do
    [n, k] <- fmap read . words <$> getLine :: IO [Int]
    ws <- fmap read . lines <$> getContents :: IO [Int]
    print $ solve k ws

