var a:array[1..1000000] of longint;
    i,j,n,m,sum,k:longint;
Begin
assign(input,'A.in');reset(input);
assign(output,'A.out');rewrite(output);
read(n);read(m);
for i:=1 to n do
begin read(k);a[k]:=a[k]+1;end;i:=0;

repeat
inc(i);
sum:=sum+a[i];
until(sum>m);
sum:=(sum-m)*i;

for j:=i+1 to 1000000 do
sum:=sum+j*a[j];
writeln(sum);
close(input);close(output);
end.