program mixjuice;
var
    cheapest : array[1..1000] of longint;
    current, n, k, i, j, total : longint;
begin
    read(n, k);
    readln;
    for i := 1 to k do
        cheapest[i] := 1000;
    total := 0;

    for i := 1 to n do begin
        read(current);
        for j := 1 to i do begin
            if current < cheapest[j] then begin
                cheapest[j] := current;
                break;
            end;
        end;
    end;

    for i := 1 to k do
        total += cheapest[i];
    writeln(total);
end.