program Main;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  filein : textfile;
  N,M : integer;
  Mass :  array of integer;


function amount_bofm:longint;
var
  i,j,pos:integer;
  amount:longint;
  biggest:integer;
begin
  amount := 0;
  for i:=1 to (N-M) do
     begin
     biggest := 0;
     pos := 0;
    //поиск максимального элемента
      for j:=1 to N do
        if Mass[j]>biggest then
          begin
          biggest := Mass[j];
          pos := j;
          end;
     Mass[pos] := 0;
     amount := amount + biggest;
     end;

   result:=amount;
end;

procedure write_result(amount:longint);
var
  fileout : textfile;
begin
  assignfile(fileout,'A.out');
  rewrite(fileout);
  writeln(fileout,amount);
  close(fileout);
end;

var
  c : integer;
begin
  assignfile(filein,'A.in');
  reset(filein);
  readln(filein,N,M);

  if (N = M) or (N < M) then
    begin
    write_result(0);
    exit;
    end;

  setlength(Mass,N+1);
  
  for c:=1 to N do
    read(filein,Mass[c]);

  write_result(amount_bofm);

  close(filein);
end.
