#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e6 + 10;
long long n, ans;
long long getAns(long long x) {
  long long ans, now, p;
  if (x == 1) {
    return 0;
  }
  if (x == 2) {
    return 1;
  }
  ans = 1;
  now = 2;
  p = 1;
  while (now << 1 <= x) {
    now <<= 1;
    ans *= 2;
    p <<= 1;
    ans += p;
  }
  if (now < x) {
    p <<= 1;
    ans += p;
    ans += getAns(x - now);
  }
  return ans;
}
int main() {
  while (scanf("%I64d", &n) != EOF) {
    if (n == 2) {
      printf("1\n");
      continue;
    }
    ans = getAns(n);
    printf("%I64d\n", ans);
  }
  return 0;
}
