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