program t2(input,output);
type
atype=array[1..100000]of longint;
var
data,f:atype;
ans:int64; n,k,i,j:longint;
procedure sort(const l,r:longint;var a:atype);
var
i, j:longint; x, y: longint;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] do j := j - 1;
if i <= j then
begin
y := a[i]; a[i] := a[j]; a[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j,a);
if i < r then Sort(i, r,a);
end;
begin
assign(input,'chess.in');
reset(input);
assign(output,'chess.out');
rewrite(output);
readln(n,k);
for i:= 1 to n do
read(data[i]);
sort(1,n,data);
for i:= 1 to n-1 do
begin
f[i]:=data[i+1]-data[i];
end;
sort(1,n-1,f);
ans:=0;
for i:= 1 to k do
ans:=ans+f[i];
writeln(ans);
close(input);
close(output);
end.