#include <bits/stdc++.h>
using namespace std;
long long p[65];
int main() {
  ios::sync_with_stdio(false);
  long long n;
  p[0] = 0;
  p[1] = 1;
  for (int i = 2; i <= 61; i++) p[i] = p[i - 1] * 2;
  cin >> n;
  n = n - 1LL;
  long long ans = 0, cnt = 1, t = 2;
  while (n / t >= 1) {
    ans += p[cnt] * (n / t);
    cnt++;
    t *= 2;
  }
  cout << ans + n << endl;
  return 0;
}
