program chop;
var
tmp,i,j,n,k:integer;
c:array [1..100] of integer;
dp:array [1..100,0..100] of longint;
begin
for i:=0 to 100 do dp[1,i]:=0;
for i:=2 to 100 do for j:=0 to 100 do dp[i,j]:=100000;
assign (input,'chop.in');
reset (input);
readln (n,k);
for i:=1 to n do read (c[i]);
for i:=1 to n-1 do for j:=i+1 to n do if (c[i]>c[j]) then begin
tmp:=c[i];
c[i]:=c[j];
c[j]:=tmp;
end;
close (input);
assign (output,'chop.out');
rewrite (output);
if 2*k+6>n then writeln (-1) else begin
dp[2,1]:=sqr(c[1]-c[2]);
for i:=3 to n do for j:=1 to i div 2 do begin
if dp[i-1,j]<dp[i-2,j-1]+sqr(c[i]-c[i-1]) then
dp[i,j]:=dp[i-1,j]
else
dp[i,j]:=dp[i-2,j-1]+sqr(c[i]-c[i-1]);
end;
writeln (dp[n,k+3]);
end;
close (output);
end.