program chess;
var
num:array [1..100001] of longint;
tmp,k,n,i:longint;
ans:int64;
procedure down(i,n:longint);
begin
while i*2<=n do begin
i:=i*2;
if (i+1<=n) and (num[i+1]>num[i]) then inc(i);
if num[i]>num[i div 2] then begin
tmp:=num[i];
num[i]:=num[i div 2];
num[i div 2]:=tmp;
end
else break;
end;
end;
procedure heapsort;
begin
for i:=n div 2 downto 1 do down(i,n);
for i:=n downto 2 do begin
tmp:=num[i];
num[i]:=num[1];
num[1]:=tmp;
down(1,i-1);
end;
end;
begin
fillchar (num,sizeof(num),0);
assign (input,'chess.in');
reset (input);
readln (n,k);
for i:=1 to n do readln (num[i]);
close (input);
assign (output,'chess.out');
rewrite (output);
heapsort;
for i:=1 to n-1 do num[i]:=num[i+1]-num[i];
dec(n);
heapsort;
for i:=1 to k do inc(ans,num[i]);
writeln (ans);
close (output);
end.