var
q,p,d,x,next,prev:array[0..100000] of longint;
dead:array[0..100000] of boolean;
s,i,j,n,t,k:longint;
ans:int64;
procedure del(l:longint);
begin
dead[l]:=true;
if prev[l]>0 then next[prev[l]]:=next[l];
if next[l]>0 then prev[next[l]]:=prev[l];
end;
procedure change(var a,b:longint);
var temp:longint;
begin
temp:=a;
a:=b;
b:=temp;
end;
procedure up(l:longint);
begin
j:=l div 2;
if (d[q[l]]<d[q[j]]) and (j>0) then begin
change(q[l],q[j]);
up(j);
end;
end;
procedure push(l:longint);
begin
inc(s);
q[s]:=l;
up(s);
end;
procedure down(l:longint);
begin
j:=2*l;
if (j+1<=s) and (d[q[j]]>d[q[j+1]]) then inc(j);
if (j<=s) and (d[q[l]]>d[q[j]]) then begin
change(q[l],q[j]);
down(j);
end;
end;
procedure pop;
begin
q[1]:=q[s];
dec(s);
down(1);
end;
function top:longint;
begin
while (dead[q[1]]) do pop;
exit(q[1]);
end;
begin
fillchar(d,sizeof(d),0);
fillchar(dead,sizeof(dead),false);
s:=0;
readln(n,k);
for i:=1 to n do readln(x[i]);
for i:=1 to n-1 do begin
d[i]:=x[i+1]-x[i];
push(i);
next[i]:=i+1;
prev[i]:=i-1;
end;
next[n-1]:=0;
for i:=1 to k do begin
t:=top;
ans:=ans+d[t];
d[t]:=-d[t];
if (next[t]>0) and (prev[t]>0) then begin
d[t]:=d[t]+d[next[t]]+d[prev[t]];
down(1);
del(next[t]);
del(prev[t]);
end
else begin
del(t);
del(next[t]);
del(prev[t]);
end;
end;
writeln(ans);
end.