program chess;
type arr=array of longint;
var n,k,i,s:longint;
A,B:arr;
procedure Qsort(var A:arr;n:longint);
procedure sort(l,r: longint);
var i,j,x,y: longint;
begin
randomize;
i:=l; j:=r;
x:=A[trunc(random(r-l))+r];
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,n);
end;
begin
assign(input,'chess.in'); reset(input);
assign(output,'chess.out'); rewrite(output);
readln(n,k);
SetLength(A,n+1); SetLength(B,n+1);
for i:=1 to n do readln(A[i]);
Qsort(A,n);
for i:=1 to n-1 do B[i]:=A[i+1]-A[i];
Qsort(B,n);
s:=0;
for i:=1 to k do s+=B[i+1];
writeln(s);
close(input); close(output);
end.