#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; int main(){ cin.tie(0); ios::sync_with_stdio(0); ll n; cin >> n; ll ans = n; for(ll i = 2; i <= ll(1e6); i++) { for(ll j = 1; pow(i, j) <= 1e18; j++) { if(n - pow(i, j) >= 0) { ll k = n - pow(i, j); ans = min(ans, i + j + k); } } } cout << ans << endl; }