#include typedef long long ll; const int maxn = 1e18; ll qmi(ll a, ll k) { ll res = 1; while (k) { if (k & 1) res = (ll)res * a; k >>= 1; a = (ll)a * a; }return res; } ll a, b, k = 1e18; int main() { ll n; scanf("%lld", &n); if (n == 1) {printf("1\n"); return 0;} if (n == 2) {printf("3\n"); return 0;} if (n == 3) {printf("4\n"); return 0;} for (ll i = 2; i * i <= n; i ++) { for (ll j = 0; qmi(i, j) <= n; j ++) { if (k > (n - qmi(i, j))) { a = i; b = j; k = std::min(k, (n - qmi(i, j))); } } }std::cout << a + b + k << "\n"; return 0; }