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

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

