#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  long long ans = 0;
  long long wt = 1;
  while (n > 1) {
    ans += wt * (n / 2);
    n = (n + 1) / 2;
    wt *= 2;
  }
  cout << ans << endl;
}
