#include #include #include #include #include using namespace std; using ll = long long; template ostream& operator<<(ostream& o, vector& v) { o << '['; for (int i = 0; i < v.size(); i++) o << (i > 0 ? ", " : "") << v[i]; o << ']'; return o; } ll llmax() { return std::numeric_limits::max(); } ll f(ll k, ll D) { // k: 跳ね返る回数 ll lo = 1; ll hi = D; ll minD = D; while (lo <= hi) { ll m = (lo + hi) / 2; ll x = m; ll d = 0; for (int i = 0; i < k; i++) { d += x; x /= 2; } if (d == D) minD = min(minD, m); if (d >= D) hi = m - 1; else lo = m + 1; } return minD; } int main() { ll D; cin >> D; ll ans = llmax(); for (int i = 1; i < 70; i++) { // 跳ね返る回数 ans = min(ans, f(i, D)); } cout << ans << endl; }