#include <bits/stdc++.h>
using namespace std;
int main() {
  unsigned long long int n;
  cin >> n;
  n--;
  vector<unsigned long long int> v;
  vector<unsigned long long int> qty;
  unsigned long long int base = 1;
  while (base <= n) {
    v.push_back(base);
    base *= 2;
  }
  for (auto e : v) {
    qty.push_back(n / e);
  }
  for (int i = qty.size() - 1; i >= 0; i--) {
    for (int j = 0; j < i; j++) {
      qty[j] -= qty[i];
    }
  }
  unsigned long long int ans = 0;
  for (int i = 0; i < qty.size(); i++) {
    ans += qty[i] * v[i];
  }
  cout << ans << endl;
  return 0;
}
