//https://yukicoder.me/submissions/630747 #include class Problem { public: void solve() { long long N; std::cin >> N; std::vector Score; while (N != 0) { Score.emplace_back(N); N /= 2; } std::cout << Score[0] * 2 - std::accumulate(Score.begin(), Score.end(), 0ll) << std::endl; } }; int main(void) { Problem solver; solver.solve(); }