import std.array, std.stdio, std.conv, std.string, std.math, std.random, std.range,std.functional;
import std.algorithm.searching, std.algorithm.sorting, std.algorithm.iteration, std.algorithm.comparison;


void main()
{
    int[] input = readln().split.to!(int[]);
    int N = input[0];
    int K = input[1];
    auto wList = iota(N).map!(a=>readln().strip.to!int).array();

    int maxWight = wList.fold!"a>b?a:b";
    writeln(search(maxWight, maxWight*N, K, wList));
}
int search(int min, int max, int k, int[] list)
{
    if(max-min==1)
    {
        if(fun(max, k, list))
        {
            return max;
        }else{
            return min;
        }
    }

    int p = min+(max-min)/2;
    if(fun(p, k, list))
    {
        return search(min, p, k, list);
    }else{
        return search(p, max, k, list);
    }
}
bool fun(int p, int k, int[] list)
{
    int ck=1;
    int cp;
    foreach(e; list)
    {
        if(cp + e <= p)
        {
            cp += e;
        }else if(ck < k){
            ck++;
            cp = e;
        }else{
            return false;
        }
    }
    return true;
}

sizediff_t minIndex(alias pred="a<b", R) (R list)
    if(isForwardRange!R && !isInfinite!R && is(typeof(binaryFun!pred(list.front, list.front))))
{
    assert(!list.empty);
    typeof(list.front) min = list.front;
    sizediff_t minPos;
    sizediff_t curPos;
    for(list.popFront(); !list.empty; list.popFront())
    {
        curPos++;

        if(binaryFun!pred(list.front, min))
        {
            min = list.front;
            minPos = curPos;
        }
    }
    return minPos;
}

