#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 1000000000;
long long n, len[100005], p[100005], st[65];
long long result = 0;
vector<pair<int, pair<int, int>>> e;
vector<int> res;
int getP(int a);
void unite(int a, int b);
long long getNearest(long long x);
long long get(long long x);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  st[0] = 1;
  for (int i = 1; i < 65; i++) st[i] = st[i - 1] + st[i - 1] + ((1LL) << i);
  cin >> n;
  cout << get(n - 1LL) << "\n";
  return 0;
  while (n--) {
    n++;
    for (int i = 0; i < n; i++) {
      len[i] = 1;
      p[i] = i;
    }
    e.clear();
    result = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++)
        e.push_back(make_pair(i ^ j, make_pair(i, j)));
    }
    sort(e.begin(), e.end());
    for (int i = 0; i < e.size(); i++) {
      int a = e[i].second.first;
      int b = e[i].second.second;
      if (getP(a) != getP(b)) {
        result += e[i].first;
        unite(a, b);
      }
    }
    cout << result << "\n";
    res.push_back(result);
    n--;
  }
  reverse(res.begin(), res.end());
  for (int i = 1; i < res.size(); i++) cout << res[i] - res[i - 1] << " ";
  return 0;
}
int getP(int a) {
  if (p[a] != a) p[a] = getP(p[a]);
  return p[a];
}
void unite(int a, int b) {
  a = getP(a);
  b = getP(b);
  if (len[a] < len[b]) swap(a, b);
  len[a] += len[b];
  p[b] = a;
}
long long getNearest(long long x) {
  long long res = 1, cur = 0;
  while (res <= x) {
    res <<= 1;
    cur++;
  }
  return cur;
}
long long get(long long x) {
  long long t = getNearest(x), ct = ((1LL) << t) - 1LL;
  if (x == ct) return st[t - 1];
  return st[t - 1] - get(ct - x);
}
