#include #define rep(i,n) for(int i=0;i<(int)(n);i++) using namespace std; using ll = long long ; using P = pair ; using pll = pair; constexpr ll INF = 1e9; constexpr long long LINF = 2e18; constexpr int MOD = 1000000007; constexpr double PI = 3.14159265358979323846; int main(){ ll d; cin >> d; ll ans = LINF; auto ok = [&](ll m,ll i){ ll res = m; rep(j,i){ res += m/2; m /= 2; } return res; }; rep(i,70){ ll l = -1,r = d+1; while(r - l > 1){ ll m = (l + r)/2; if(ok(m,i) >= d) r = m; else l = m; } if(ok(r,i) == d) ans = min(ans,r); } cout << ans << endl; return 0; }