program kuaizi;
var
d,k,n,i,j:longint;
a:array[1..100]of longint;
f:array[0..100,0..50]of longint;
function min(a,b:longint):longint;
begin
if a<b then
min:=a
else
min:=b
end;
begin
assign (input,'chop.in');
reset (input);
assign (output,'chop.out');
rewrite (output);
readln (n,k);
for i:=1 to n do
read (a[i]);
for i:=1 to n-1 do
for j:=i+1 to n do
if a[i]>a[j] then
begin
d:=a[i];
a[i]:=a[j];
a[j]:=d
end;
k:=k+3;
for i:=0 to n do
for j:=1 to k do
f[i,j]:=999999999;
for i:=0 to n do
f[i,0]:=0;
if k*2>n then writeln ('-1')
else
begin
for i:=2 to n do
for j:=1 to k do
f[i,j]:=min(f[i-1,j],f[i-2,j-1]+sqr(a[i]-a[i-1]));
writeln (f[n,k])
end;
close (input);
close (output)
end.