#include #define rep(i,n) for(int i = 0; i < (n); i++) using namespace std; typedef long long ll; bool ok(ll a, ll d){ ll x = a; while(x != 0){ x /= 2; a += x; } return (a >= d); } int main(){ cin.tie(0); ios::sync_with_stdio(0); ll D; cin >> D; ll r = D+10; ll l = 0; while(r - l > 1){ ll mid = (r + l) / 2; if(ok(mid, D)) r = mid; else l = mid; } bool ok = false; ll s = r, x = r; while(x > 0){ if(s == D) ok = true; x /= 2; s += x; } if(ok) cout << r << endl; else cout << D << endl; }