#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = (ll)4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    ll d;
    cin >> d;
    ll l = -1, r = d + 1, ans = d;
    while (r - l > 1) {
        ll m = (l + r) / 2;
        ll sum = 0, t = m;
        while (t) {
            sum += t;
            t /= 2;
            if (sum == d) chmin(ans, m);
        }
        if (sum >= d) {
            r = m;
        } else {
            l = m;
        }
        if (sum == d) chmin(ans, r);
    }
    cout << ans << endl;
    return 0;
}