#include #define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++) using namespace std; typedef long long ll; int main(void) { ll N; cin >> N; ll cnt = 0; REP(i, 0, 63) if(N & (1LL << i)) cnt++; ll p = 1; REP(i, 0, cnt) p *= 2; cout << N + 1 - p << endl; }