#include using namespace std; int main() { ios::sync_with_stdio(false); int64_t D; { cin >> D; } int64_t lb = 0; int64_t ub = D; while (ub - lb > 1) { int64_t mb = lb + ub >> 1; int64_t s = 0; for (int64_t u = mb; u; u >>= 1) { s += u; } (s >= D ? ub : lb) = mb; } auto test = [D](int64_t v) { int64_t r = 0; while (v && r < D) r += v, v /= 2; return r == D; }; while (!test(ub)) ub += 1; cout << ub << endl; }