#include #include #include #include #include #include #include #include #include #include #include #include #include #define loop(i,a,b) for(int i=a;i pii; typedef vector vi; typedef vector vvi; typedef vector vp; typedef vector vvp; typedef pair pip; typedef vectorvip; const double PI=acos(-1); const double EPS=1e-8; const ll inf=1<<60; int main(){ ll in; cin>>in; ll out=inf; for(ll i=1;i*i<=in;i++)if(in%(i+1)==0){ ll t=in/(i+1); if(t==1)out=min(out,i); else{ for(ll j=1;j*j<=t;j++)if(t%(j+1)==0) out=min(out,i+j+t/(j+1)-1); } } if(out==inf)out=in-1; cout<