program t2(input,output);
type
atype=array[1..100000]of integer;
var
data,f:atype;
ans:int64; n,k,i,j:longint;
procedure sort(l,r:longint;var a:atype);
var
i, j:longint; x, y: integer;
begin
i := l; j := r; x := a[(l+r) DIV 2];
repeat
while a[i] < x do i := i + 1;
while x < a[j] do j := j - 1;
if i <= j then
begin
y := a[i]; a[i] := a[j]; a[j] := y;
i := i + 1; j := j - 1;
end;
until i > j;
if l < j then Sort(l, j,a);
if i < r then Sort(i, r,a);
end;
begin
assign(input,'chess.in');
reset(input);
assign(output,'chess.out');
rewrite(output);
readln(n,k);
for i:= 1 to n do
read(data[i]);
sort(1,n,data);
if not odd(n) then data[n+1]:=maxint;
for i:= 1 to n div 2 do
begin
f[i*2-1]:=data[i*2]-data[i*2-1];
f[i*2]:=data[i*2+1]-data[i*2];
end;
sort(1,n-1,f);
ans:=0;
for i:= 1 to k do
ans:=ans+f[i];
writeln(ans);
close(input);
close(output);
end.