program zada;

{$APPTYPE CONSOLE}

var
  a:array[1..1000000] of integer;
  i,j:integer;
  n,m,c,max,s:integer;
begin
  assignfile(input,'input.txt');
  reset(input);
  assignfile(output,'output.txt');
  rewrite(output);
  read(n,m);
  fillchar(a,n,0);
  read(c);
  a[c]:=a[c]+1;
  max:=c;
  for i:=2 to n do
    begin
      read(c);
      a[c]:=a[c]+1;
      if c>max then max:=c;
    end;
  s:=0;
  for i:=1 to max do
    begin
      m:=m-a[i];
      if m<0 then
        begin
          for j:=1 to m*(-1) do
            s:=s+i;
          break;
        end
      else
        if m=0 then break;
    end;
  for j:=i to max do
    if a[j]>0 then
      s:=s+j;
  write(s);
  closefile(output);
end.
