#include using namespace std; using ll = long long; constexpr char newl = '\n'; ll calc(ll x, ll lim) { ll res = 0; while (x >= lim) { res += x; x >>= 1; } return res; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); ll d; cin >> d; ll lim = 1; ll ans = d; while (true) { ll ng = 0, ok = d; while (ok - ng > 1) { ll mid = (ok + ng) / 2; (calc(mid, lim) >= d ? ok : ng) = mid; } if (calc(ok, lim) == d) { ans = ok; break; } lim <<= 1; } cout << ans << newl; return 0; }