#include //#include //using namespace atcoder; using namespace std; #pragma region Macros using ll = long long; #define int ll using pii = pair; using tiii = tuple; template using V = vector; template using VV = V>; #define IOS\ ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0); #define FOR(i,l,r) for(int i=(l);i=int(r);--i) #define RREP(i,n) RFOR(i,n-1,0) #define RREPS(i,n) RFOR(i,n,1) #define mp make_pair #define mt make_tuple #define pb push_back #define eb emplace_back #define all(x) (x).begin(),(x).end() #define SORT(name) sort(name.begin(), name.end()) #define RSORT(name)\ SORT(name);\ reverse(all(name)); #define ZERO(p) memset(p, 0, sizeof(p)) #define MINUS(p) memset(p, -1, sizeof(p)) inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';} inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';} template inline void print(T x){ cout << x << '\n';} template inline void chmin(T1 &a, T2 b){ if(a > b) a = b; } template inline void chmax(T1 &a, T2 b){ if(a < b) a = b; } const ll LLINF = (1LL<<62); const int INF = (1LL<<30); const double DINF = std::numeric_limits::infinity(); #pragma endregion const int MOD = 1000000007; #if 1 # define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__) #else # define DBG(fmt, ...) #endif const int MAX_N = 100010; int D; bool Check(int x) { int cur = 0; while(x > 0) { cur += x; if(cur == D) { return true; } x /= 2; } return false; } int GetDist(int x, int k) { int cur = 0; REP(i, k) { cur += x; x /= 2; } return cur; } signed main() { IOS; cin >> D; // x 回はねたことにする int ans = LLINF; for(int x = 0; x < 63; ++x) { int lb = 0, ub = D; while(ub - lb > 1) { int mid = (ub + lb) / 2; int val = GetDist(mid, x); if(val == D) { chmin(ans, mid); ub = mid; } else if(val < D) { lb = mid; } else { ub = mid; } } if(Check(lb)) { chmin(ans, lb); } if(Check(ub)) { chmin(ans, ub); } } print(ans); return 0; }