#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
  long long ret = 1;
  while (b) {
    if (b & 1) ret *= a;
    a *= a;
    if (ret >= MOD) ret %= MOD;
    if (a >= MOD) a %= MOD;
    b >>= 1;
  }
  return ret;
}
long long inv(long long x) { return power(x, MOD - 2); }
const int N = 1e5 + 5;
long long n;
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long ans = 0, wei = 1;
  while (n > 1) {
    ans += wei * (n / 2);
    wei *= 2;
    n = (n + 1) / 2;
  }
  cout << ans;
}
