program xxxx;
var n,k,p,w:longint;
a:array[1..100000] of longint;
procedure paixu(l,r:longint);
var i,j,mid,temp:longint;
begin
i:=l;
j:=r;
mid:=a[l+random(r-l+1)];
repeat
while a[i]<mid do
inc(i);
while mid<a[j] do
dec(j);
if i<=j then
begin
temp:=a[i];
a[i]:=a[j];
a[j]:=temp;
inc(i);
dec(j);
end;
until i>j;
if l<j then
paixu(l,j);
if i<r then
paixu(i,r);
end;
begin
assign(input,'chess.in');
reset(input);
assign(output,'chess.out');
rewrite(output);
read(n,k);
for p:=1 to n do
read(a[p]);
paixu(1,n);
for p:=1 to n-1 do
a[p]:=a[p+1]-a[p];
paixu(1,n-1);
w:=0;
for p:=1 to k do
w:=w+a[p];
write(w);
close(input);
close(output);
end.