/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

#ifndef DEFINE_MATH_HPP
#define DEFINE_MATH_HPP

class Math
{
    ll mod = 1e9+7;
  public:
    template<typename T> int keta(T num);
    template<typename T1, typename T2> ll gcd(T1 a, T2 b);
    template<typename T1, typename T2> ll lcm(T1 a, T2 b);
    template<typename T1, typename T2> ll powmod(T1 num1, T2 num2);
    template<typename T1, typename T2> ll powl(T1 a, T2 b);
};

#endif //DEFINE_MATH_HPP

template<typename T1, typename T2>
ll Math::gcd(T1 a, T2 b)
{
    if(b==0) return a;
    return gcd(b, a%b);
}

template<typename T1, typename T2>
ll Math::lcm(T1 a, T2 b){
    return a*(b/gcd(a, b));
}

template<typename T>
int Math::keta(T num){
    T k=0;
    while(num>0){
        num/=10;
        k++;
    }
    return k;
}

template<typename T1, typename T2>
ll Math::powmod(T1 num1, T2 num2){
    ll res = 1;
    while(num2 > 0){
        res *= num1;
        res %= mod;
        num2--;
    }
    return res%mod;
}

template<typename T1, typename T2>
ll Math::powl(T1 a, T2 b){
    ll res = 1;
    while(b > 0){
        res *= a;
        b--;
    }
    return res;
}

class DCaracalVsMonster {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    ll h;
	    in >> h;

	    ll cnt = 0;
	    ll buf = h;
	    ll res = 0;
	    ll sq = 1;
	    while(buf > 1){
	        cnt++;
	        buf /= 2;
	        res += sq;
	        sq *= 2;
	    }

	    Math mt;
	    res = mt.powl(2, cnt+1);
//
//	    while(cnt > 1){
//	        res += mt.powl(2, cnt);
//	        cnt--;
//	    }

	    out << res-1 << endl;
	}
};


int main() {
	DCaracalVsMonster solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256