program chop;
var
i1,i2,i3,n,k,min,max,c1,c2:longint;
sz,sz2:array[1..100]of longint;
begin
assign(input,'chop.in');
assign(output,'chop.out');
reset(input);
rewrite(output);
readln(n,k);
fillchar(sz2,sizeof(sz2),0);
if n<(k+3) then begin
writeln(-1);
end
else begin
for i1:=1 to n do
read(sz[i1]);
for i1:=1 to k+3 do
begin
min:=32767;
for i2:=1 to n-1 do
begin
for i3:=i2+1 to n do
begin
if (abs(sz[i2]-sz[i3])<min)and(sz2[i2]=0)and(sz2[i3]=0) then begin
min:=abs(sz[i2]-sz[i3]);
c1:=i2;
c2:=i3;
end;
end;
end;
max:=max+min*min;
sz2[c1]:=1;
sz2[c2]:=1;
end;
writeln(max);
end;
close(input);
close(output);
end.