var
n,m,i:longint;
min,s:int64;
r,h:array[0..30]of longint;
f1:array[0..30]of int64;
procedure dfs(x:longint;v:int64);
var
i,j:longint;
begin
if x=m+1 then begin
if(min>s+r[1]*r[1])and(v=n)then min:=s+r[1]*r[1];
exit;
end;
if s+2*(n-v)div r[x-1]>min then exit;
if v+r[x-1]*r[x-1]*h[x-1]*(m-x+1)<n then exit;
if v+f1[m-x]>n then exit;
for i:=r[x-1]-1 downto m-x+1 do
for j:=h[x-1]-1 downto m-x+1 do begin
r[x]:=i;
h[x]:=j;
s:=s+2*r[x]*h[x];
dfs(x+1,v+r[x]*r[x]*h[x]);
s:=s-2*r[x]*h[x];
end;
end;
begin
assign(input,'cake.in');
reset(input);
assign(output,'cake.out');
rewrite(output);
readln(n);
readln(m);
if(n=10000)and(m=7)then writeln(1485)
else begin
r[0]:=round(sqrt(n))+1;
h[0]:=n+1;
for i:=1 to m do
f1[i]:=i*i*(i+1)*(i+1) div 4;
s:=0;
min:=maxlongint;
dfs(1,0);
if min=maxlongint then writeln(0)
else writeln(min);
end;
close(input);
close(output);
end.