#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i;
  cin >> n;
  vector<long long int> v;
  for (i = 0; pow(2, i) < n; i++) {
    v.push_back(pow(2, i));
  }
  long long int t;
  long long int sum = 0, count = n - 1;
  for (i = v.size() - 1; i > 0; i--) {
    t = (n - 1) / v[i];
    if (t > 0) {
      if (t % 2 == 0) t = t - 1;
      sum += v[i] * 1ll * ((t - 1) / 2 + 1);
      count -= ((t - 1) / 2 + 1);
    }
  }
  cout << sum + count << " ";
  return 0;
}
