#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 f(ll k, ll D) { // k: 跳ね返る回数 ll lo = 1; ll hi = D; ll minD = D; while (lo <= hi) { // ll m = (lo + hi) / 2; ll m = lo + (hi - lo) / 2; ll x = m; // 最初の飛距離 ll r = 0; // 跳ね返る回数 ll d = 0; // トータル飛距離 while (x > 0) { d += x; x /= 2; r++; //if (r > k) break; } if (r == k && d == D) { minD = min(minD, m); hi = m - 1; } if (d >= D) hi = m - 1; else lo = m + 1; } return minD; } int main() { ll D; cin >> D; ll ans = D; for (int i = 1; i < 70; i++) { // 跳ね返る回数 ans = min(ans, f(i, D)); //printf("%d %lld\n", i, f(i, D)); } cout << ans << endl; }