#include using namespace std; const double pi = 2 * acos(0.0); const double eps = 1e-8; #define REP(i,a,b) for(int i=(a); i<(b);++i) #define rep(i,n) REP(i,0,n) #define INF (1<<29) #define INFLL (1LL<<61) typedef long long ll; typedef unsigned long long ull; typedef pair pii; typedef pair pll; int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; int dy[8] = {1, 0, -1, 0, 1, -1, -1, 1}; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); ll N, T; cin >> N; ll NC = 0; T = N; while (T != 0) { NC += T; T /= 2; } ll ans = -1; for (int i = 0; i < 61; i++) { ll S = 0; T = N; for (int j = 0; T != 0; j++, T /= 2) { if (j == i) { S += T * 2; break; } else { S += T; } } ans = max(S, ans); } ans = ans - NC; cout << ans << endl; return 0; }