program chess(input,output);
type
tlist=array[1..100000]of longint;
var
n,k,i,j:longint;
lv:tlist;
procedure qsort(var a:tlist; const max:longint);
procedure sort(l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=a[(l+r) div 2];
repeat
while a[i]<x do
inc(i);
while x<a[j] do
dec(j);
if not(i>j) then
begin
y:=a[i];
a[i]:=a[j];
a[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if l<j then
sort(l,j);
if i<r then
sort(i,r);
end;
begin
sort(1,max);
end;
begin
assign(input,'chess.in');
reset(input);
assign(output,'chess.out');
rewrite(output);
readln(n,k);
for i:=1 to n do
readln(lv[i]);
qsort(lv,n);
for i:=1 to n-1 do
lv[i]:=lv[i+1]-lv[i];
qsort(lv,n);
n:=0;
for i:=1 to k do
n:=n+lv[i];
writeln(n);
close(input);
close(output);
end.