#include <bits/stdc++.h>
using namespace std;
long long inf1 = 1e18;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long n;
  cin >> n;
  long long ans = 0, mul = 1;
  bool temp = 0;
  while (1) {
    if (n == 1) break;
    ans += (n / 2) * mul;
    if (n & 1 && temp) {
      ans += mul;
      n--;
    } else if (n & 1)
      n--, temp = 1;
    mul *= 2;
    n /= 2;
  }
  if (temp) ans += mul;
  cout << ans;
}
