program chess;
var
n,k,i,j,t,sum:longint;
a,cha:array[1..10000] of longint;
begin
assign(input,'chess.in');
assign(output,'chess.out');
reset(input);
rewrite(output);
readln(n,k);
for i:=1 to n do readln(a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then begin
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
for i:=1 to n-1 do cha[i]:=a[i+1]-a[i];
for i:=1 to n-2 do
for j:=i+1 to n-1 do
if cha[i]>cha[j] then begin
t:=cha[i];
cha[i]:=cha[j];
cha[j]:=t;
end;
for i:=1 to k do sum:=sum+cha[i];
writeln(sum);
close(input);
close(output);
end.
end.