#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const long long inf = 1e18 * 2ll;
int main() {
  long long n;
  while (cin >> n) {
    long long res = 0;
    long long fac = 1;
    while (n > 1) {
      long long numLinks = n / 2;
      res += fac * numLinks;
      fac *= 2;
      n = n / 2 + n % 2;
    }
    cout << res << endl;
  }
  return 0;
}
