#include #define rep(i,n) for(ll i = 0; i < (n); ++i) #define srep(i,s,t) for (ll i = s; i < t; ++i) #define drep(i,n) for(ll i = (n)-1; i >= 0; --i) using namespace std; typedef long long int ll; typedef pair P; #define yn {puts("YES");}else{puts("NO");} #define MAX_N 200005 ll ans; void dfs(ll d, ll k, ll ma, ll tmp){ if(ma<0){ if(d == 0){ ans = min(ans, tmp); } return; } while(ma>=0){ ll dd = d; ll ttmp = tmp + (1LL<0){ dfs(dd,k,ma-1,ttmp); } ma--; } } int main() { ll D; cin >> D; ans = D; srep(i,2,61){ dfs(D,i,62,0); } cout << ans << endl; return 0; }