program chess;
var
a,ans:array [1..10000] of longint;
n,k:longint;
f1,f2:text;
procedure init;
var i:longint;
begin
assign(f1,'chess.in'); reset(f1);
assign(f2,'chess.out'); rewrite(f2);
readln(f1,n,k);
for i:=1 to n do
readln(f1,a[i]);
close(f1);
end;
procedure qsort(x,y:longint);
var l,r,k,temp:longint;
begin
l:=x;
r:=y;
k:=a[(x+y) div 2];
repeat
while a[l]<k do inc(l);
while a[r]>k do dec(r);
if l<=r then begin
temp:=a[l];
a[l]:=a[r];
a[r]:=temp;
inc(l); dec(r);
end;
until l>r;
if r>x then qsort(x,r);
if l<y then qsort(l,y);
end;
procedure play;
var i,s:longint;
begin
s:=0;
qsort(1,n);
for i:=1 to n-1 do
a[i]:=a[i+1]-a[i];
qsort(1,n-1);
for i:=1 to k do
s:=s+a[i];
writeln(f2,s);
close(f2);
end;
begin
init;
play;
end.