uses
    math;
const
    max_k = 1000000;
    max_p = 100000;
var
    a: array [1..max_k] of longint;

procedure qsort(l, r: longint);
var
    i, j: longint;
    x, t: longint;
begin
    x := a[l + random(r - l + 1)];
    i := l;
    j := r;
    while (i <= j) do begin
        while (a[i] < x) do inc(i);
        while (a[j] > x) do dec(j);
        if (i <= j) then begin
            t := a[i]; a[i] := a[j]; a[j] := t;
            inc(i);
            dec(j);
        end;
    end;
    if (l <= j) then qsort(l, j);
    if (i <= r) then qsort(i, r);
end;

var
    i, k, p: longint;
    s, r: int64;
begin
    reset(input, 'trees.in');
    rewrite(output, 'trees.out');

    while not seekeof do begin
        read(k, p);
        
        for i := 1 to k do begin
            read(a[i]);
        end;

        if (k < p) then begin
            writeln(k);
            continue;
        end;

        qsort(1, k);

        s := 0;
        for i := 1 to k - p + 1 do begin
            s := s + a[i];
        end;

        r := s;
        for i := 2 to p do begin
            r := r + min(a[k - p + i], r div (i - 1) + 1);
        end;
        writeln(r);
    end;

    close(input);
    close(output);
end.
