#include #define rep(i, n) for(int i = 0; i < n; i++) using namespace std; typedef long long ll; const int INF = 1 << 30; const ll LLINF = 1LL << 62; int mod = 1000000007; int main(void){ ios::sync_with_stdio(false); cin.tie(nullptr); ll D; cin >> D; ll ans = LLINF; for(int jmp = 0; jmp <= 60; jmp++){ ll ok = D, ng = -1; ll m = (ok+ng)/2; while(abs(ok-ng) > 1){ ll temp = m; ll res = m; int cnt = 0; while(temp > 0 && cnt < jmp){ res += temp/2; temp >>= 1; cnt++; } if(res >= D) ok = m; else ng = m; m = (ok+ng)/2; } ll dlim = ok; for(ll i = dlim; i <= dlim; i++){ ll acc = i; ll temp = i; int cnt = 0; while(temp > 0 && cnt < jmp){ acc += temp/2; temp >>= 1; cnt++; } if(acc == D) ans = min(ans, i); } } cout << ans << endl; return 0; }