#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; constexpr int INF = 1001001001; constexpr int mod = 1000000007; // constexpr int mod = 998244353; template inline bool chmax(T& x, T y){ if(x < y){ x = y; return true; } return false; } template inline bool chmin(T& x, T y){ if(x > y){ x = y; return true; } return false; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll D; cin >> D; ll lb = 0, ub = D; while(ub - lb > 1){ ll mid = (lb + ub) / 2; ll sum = mid, x = mid; while(x > 0){ sum += x / 2; x /= 2; } if(sum >= D) ub = mid; else lb = mid; } ll sum = ub, x = ub; bool ok = sum == D; while(x > 0){ sum += x / 2; x /= 2; ok |= sum == D; } ll ans = ub; if(!ok) ans = D; cout << ans << endl; return 0; }