#include <bits/stdc++.h>
using namespace std;
const double EPS = (double)1e-9;
const double PI = (double)acos(-1.0);
int irand(int lo, int hi) {
  return (((double)rand()) / (RAND_MAX + 1.0)) * (hi - lo + 1) + lo;
}
string toString(long long x) {
  stringstream ss;
  ss << x;
  return ss.str();
}
long long toNumber(string S) {
  long long ret;
  sscanf(S.c_str(), "%lld", &ret);
  return ret;
}
const int INF = (int)2e9;
const long long MOD = (long long)1e9 + 7;
int main() {
  long long n, res = 0, two = 1;
  scanf("%lld", &n);
  while (n > 1) {
    res += two * (n / 2);
    n = (n / 2) + (n % 2);
    two <<= 1;
  }
  printf("%lld\n", res);
  return 0;
}
