program chop;
const
maxn = 110;
maxk = 55;
Inf =100000000;
var
n,k: longint;
A: array[1..maxn] of longint;
f: array[0..maxn,0..maxk] of longint;
function min(a,b:longint):longint;
begin
if a <b then exit(a) else exit(b);
end;
procedure init;
var
i,j,temp: longint;
begin
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
temp :=A[i]; A[i] :=A[j]; A[j] :=temp;
end;
end;
procedure main;
var
i,j: longint;
begin
if (k+3)*2 >n then begin writeln(-1); exit; end;
inc(k,3);
for j :=1 to k do
for i :=1 to n do
f[i][j] :=Inf;
for j :=1 to k do
for i :=j*2 to n do begin
f[i][j] :=min(f[i][j],f[i-2][j-1]+ sqr(A[i-1]-A[i]) );
if i >j*2 then f[i][j] :=min(f[i][j],f[i-1][j]);
end;
writeln(f[N][K]);
end;
begin
assign(input,'chop.in'); reset(input);
assign(output,'chop.out'); rewrite(output);
init;
main;
close(input); close(output);
end.