var
n,k,i,j:longint;
a:array[0..100000]of longint;
procedure Sort(l, r: Integer);
var
i, j, x, y: integer;
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);
if i < r then Sort(i, r);
end;
begin
assign(input,'chess.in');reset(input);
assign(output,'chess.out');rewrite(output);
readln(n,k);
for i:=1 to n do readln(a[i]);
sort(1,n);
for i:=1 to n-1 do a[i]:=a[i+1]-a[i] ;
sort(1,n-1);
j:=0;
for i:=1 to k do j:=j+a[i];
writeln(j);
close(input);close(output);
end.