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