Program chop;
Type
sc=array [0..100,0..100] of longint;
sc1=array [1..100] of longint;
Var
s:sc;
a:sc1;
i,j,p:longint;
n,m,k,temp,min,temp1:longint;
Begin
assign(input,'chop.in');
assign(output,'chop.out');
reset(input);
rewrite(output);
readln(n,k);
for i:=1 to n do read(a[i]);
for i:=1 to (n-1) do begin
for j:=(i+1) to n do begin
if a[i]>a[j] then begin
temp:=a[j];
a[j]:=a[i];
a[i]:=temp;
end;
end;
end;
k:=k+3;
if (n div 2)<k then writeln('-1')
else begin
for i:=0 to 100 do
for j:=1 to 100 do
s[i,j]:=9999999;
for i:=1 to n do begin
for j:=1 to k do begin
s[i,j]:=s[i-1,j];
for p:=1 to (i-1) do begin
temp:=s[p-1,j-1]+(a[p]-a[i])*(a[p]-a[i]);
if temp<s[i,j] then s[i,j]:=temp;
end;
end;
end;
end;
writeln(s[n,k]);
close(input);
close(output);
End.