#include <bits/stdc++.h>
using namespace std;
const int MAXN = 40;
long long N;
long long L[MAXN], R[MAXN];
long long sumaindice(long long n, long long x) {
  assert(x < L[n]);
  if (n == 0) return 1;
  if (x < L[n - 1]) return sumaindice(n - 1, x);
  if (x == L[n - 1])
    return R[n - 1] + (1LL << n);
  else
    return R[n - 1] + (1LL << n) + sumaindice(n - 1, x - L[n - 1] - 1);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> N;
  N -= 2;
  L[0] = R[0] = 1;
  for (int i = 1; i < int(MAXN); ++i) {
    L[i] = 2 * L[i - 1] + 1;
    R[i] = 2 * R[i - 1] + (1LL << i);
  }
  cout << sumaindice(MAXN - 1, N) << endl;
  return 0;
}
