var
  a: array [1..101000] of int64;
  i,n,q,mx:longint;
  ans,w,k:int64;

begin
  assign(input,'A.in');
  reset(input);
  assign(output,'A.out');
  rewrite(output);
  read(n,k);
  k:=n-k;
  fillchar(a,sizeof(a),0);
  mx:=0;
  for i:=1 to n do begin
    read(q);
    inc(a[q]);
    if q>mx then mx:=q;
  end;
  ans:=0;
  for i:=mx downto 1 do 
    if a[i]>0 then begin
      w:=i;
      if k>=a[i] then begin
        ans:=ans+a[i]*w;
        k:=k-a[i];
      end else if k>0 then begin
        ans:=ans+k*w;
        k:=0;        
      end else if k=0 then break;
    end;
  writeln(ans); 
  close(output);
end.