#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const long long maxN = 1e6, oo = 1e9, MOD = 1e9 + 7;
using namespace std;
ll n, res = 0;
void readInput() { cin >> n; }
void process() {
  ll tmp = 0;
  for (ll i = 40; i >= 0; --i) {
    ll num = ((n - 1) / (1LL << i)) - tmp;
    res += (num * (1LL << i));
    tmp += num;
  }
}
void writeOutput() { cout << res; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  readInput();
  process();
  writeOutput();
}
