n, k = gets.chomp.split.map(&:to_i)
ws = Array.new

n.times do
    ws << gets.chomp.to_i
end

row  = ws.max
high = ws.sum

def mlc(row, high, ws, k)
    mid = (row + high) / 2

    if high - row <= 1 then
        if loadable?(k, ws, row) then
            row
        else
            high
        end
    else
        if loadable?(k, ws, mid) then
            mlc(row, mid, ws, k)
        else
            mlc(mid, high, ws, k)
        end
    end
end

def loadable?(k, ws, p)
    track = 1
    loaded = 0

    ws.each do |w|
        if loaded + w > p then
            track += 1
            loaded = w
        else
            loaded += w
        end
    end
    track <= k
end

p mlc(row, high, ws, k)
