#include<bits/stdc++.h>
using namespace std;
int n,m,ans=INT_MAX,ch1[22]= {0,1,9,36,100,225,441,784,1296,2025,3025,4356,6084,8281,11025,14400,18496,23409,29241,36100,44100},ch3[22]= {0,2,10,28,60,110,182,280,408,570,770,1012,1300,1638,2030,2480,2992,3570,4218,4940,5740};
void dfs(int step,int left,int rl,int hl,int S) {
if(left<ch1[step])return;
if(S+ch3[step]>=ans)return;
if(!step) {
if(!left&&S<ans)ans=S;
return;
}
int r=sqrt(left);
for(int r=min(rl-1,r); r>=step; r--) {
if(r/2<=min(left/(r*r),hl-1)&&r/2>=step) {
if(step==m)dfs(step-1,left-r*r*r/2,r,r/2,S+r*2*r/2+r*r);
else dfs(step-1,left-r*r*r/2,r,r/2,S+r*2*r/2);
}
for(int h=min(left/(r*r),hl-1); h>=step; h--) {
if(step==m)dfs(step-1,left-r*r*h,r,h,S+r*2*h+r*r);
else dfs(step-1,left-r*r*h,r,h,S+r*2*h);
}
}
}
int main() {
cin>>n>>m;
if(ch1[m]>n) {
cout<<0<<endl;
return 0;
}
dfs(m,n,sqrt(n),sqrt(n),0);
cout<<ans<<endl;
return 0;
}