#include #include using namespace std; int main(){ long long a;cin>>a; long long ans =(long long)sqrt(a)+2+a-(long long)sqrt(a)*(long long)sqrt(a); for(int i = 2; 1000001 > i; i++){ long long nw = 1; for(int j = 0; a >= nw; j++){ if(ans == -1)ans = i+j+a-nw; else ans = min(ans,i+j+a-nw); nw *= i; } } cout << ans << endl; }