program chess;
var a,b:array[1..100000]of longint;
t,k,m,n,i,j:longint;
procedure qsort(l,r:longint);
var t,k,i,c:longint;
begin
t:=l;
k:=r;
i:=a[(l+r)div 2];
repeat
while a[t]<i do inc(t);
while a[k]>i do dec(k);
if t<=k then
begin
c:=a[t];
a[t]:=a[k];
a[k]:=c;
inc(t);
dec(k);
end;
until t>k;
if t<r then qsort(t,r);
if l<k then qsort(l,k);
end;
begin
assign(input,'chess.in');
reset(input);
assign(output,'chess.out');
rewrite(output);
readln(n,m);
for t:=1 to n do
readln(a[t]);
qsort(1,n);
for t:=1 to n do
a[t]:=a[t+1]-a[t];
qsort(1,n-1);
for t:=1 to m do
i:=i+a[t];
writeln(i);
close(output);
end.