program t4;
var
a:array[0..100] of longint;
n,m,i,k,j,t,ans:longint;
f:array[0..100,0..53] of longint;
begin
assign(input,'chop.in');
assign(output,'chop.out');
reset(input);
rewrite(output);
readln(n,m);
m:=m+3;
ans:=maxlongint;
if n<m*2
then writeln(-1)
else
begin
for i:=1 to n do read(a[i]);
for i:=1 to n-1 do
begin
j:=i;
for k:=i+1 to n do
if a[k]<a[j]
then j:=k;
t:=a[i];
a[i]:=a[j];
a[j]:=t;
end;
fillchar(f,sizeof(f),100);
for i:=0 to n do
f[i,0]:=0;
for i:=1 to n do
begin
for j:=1 to m do
begin
f[i,j]:=f[i-1,j];
for k:=1 to i-1 do
begin
t:=f[k-1,j-1]+sqr(a[i]-a[k]);
if t<f[i,j] then f[i,j]:=t;
end;
end;
end;
writeln(f[n,m]);
end;
close(input);
close(output);
end.