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().sort!"a>b"();
    int[] onList;
    onList.length = K;
    foreach(w; wList)
    {
        onList[onList.minIndex] += w;
    }
    writeln(onList.maxElement);
}

sizediff_t minIndex(alias pred="a<b", R) (R list)
    if(isForwardRange!R && !isInfinite!R && is(typeof(binaryFun!pred(list.front, list.front))))
{
    if(list.empty) return -1;

    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;
}

auto maxElement(alias pred="a<b", R) (R list)
    if(isForwardRange!R && !isInfinite!R && is(typeof(binaryFun!pred(list.front, list.front))))
{
    if(list.empty) return -1;

    ElementType!R max = list.front; list.popFront();
    foreach(e; list)
    {
        if(binaryFun!pred(max, e))
            max = e;
    }
    return max;
}
