program chess(input,output);
type
tlist=array[1..100000]of longint;
var
n,k,i,j:longint;
lv:tlist;
procedure qsort(const l,r: longint);
var
i,j,x,y: longint;
begin
i:=l;
j:=r;
x:=lv[(l+r)div 2];
repeat
while lv[i]<x do
inc(i);
while x<lv[j] do
dec(j);
if i<=j then
begin
y:=lv[i];
lv[i]:=lv[j];
lv[j]:=y;
inc(i);
dec(j);
end;
until i>j;
if l<j then
qsort(l,j);
if i<r then
qsort(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(lv[i]);
qsort(1,n);
for i:=1 to n-1 do
lv[i]:=lv[i+1]-lv[i];
qsort(1,n-1);
n:=0;
for i:=1 to k do
n:=n+lv[i];
writeln(n);
close(input);
close(output);
end.