#include                            <iostream>
#include							<list>
#include                            <stdio.h>
#include                            <math.h>
#include                            <string.h>
#include                            <time.h>
#include                            <stdlib.h>
#include                            <string>
#include                            <bitset>
#include                            <vector>
#include                            <set>
#include                            <map>
#include                            <queue>
#include                            <algorithm>
#include                            <sstream>
#include                            <stack>
#include                            <iomanip>
#include                            <numeric>
#include							<unordered_map>
using namespace                     std;
#define int                         int64_t
#define baba_shiv                   ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mpii                        map<int,int>
#define pb                          push_back
#define mkp                         make_pair
#define all(x)                      x.begin(),x.end()
#define allr(x)                     x.rbegin(),x.rend()
#define ub(v,x)                     upper_bound(all(v),x)
#define lb(v,x)                     lower_bound(all(v),x)
#define bs(v,x)                     binary_search(all(v),x)
#define gcd(a,b)                    __gcd(a,b)
#define lcm(a,b)                    (a*b)/__gcd(a,b)
#define vi                          vector<int>
#define pii                         pair<int,int>
#define vpii                        vector<pii>
#define vs                          vector<string>
#define ff                          first
#define ss                          second
#define MOD                         1000000007
#define double						long double
/***********************************************************************************************************************/
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	typename vector< T > :: const_iterator it;
	for ( it = v.begin(); it != v.end(); it++ ) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	typename set< T > :: const_iterator it;
	for ( it = v.begin(); it != v.end(); it++ ) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	typename map< F , S >::const_iterator it;
	for ( it = v.begin(); it != v.end(); it++ ) {
		if ( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
	return os << "]";
}

#define deb(x) cerr<< #x << " = " << x << endl;

/***********************************************************************************************************************/
const int siz = 2e5 + 7;
vector<int> adj[siz];
vector<bool>visited(siz);
int shortest_path_sunny(int source , int dest)
{
	vector<int> dist(siz, 1e18);
	dist[source] = 0;
	queue<int> q;
	q.push(source);
	int u;
	while (!q.empty())
	{
		u = q.front();
		for (int i = 0; i < adj[u].size(); i++)
		{
			if (dist[adj[u][i]] > dist[u] + 1)
			{
				dist[adj[u][i]] = dist[u] + 1;
				q.push(adj[u][i]);
			}
		}
		q.pop();
	}

	if (dist[dest] == 1e18)
		return -1;
	int count = 0;
	for (auto it : dist)
	{
		if (it != 1e18 && it < dist[dest])
			count++;
	}
	return count;
}
signed main()
{
	baba_shiv;
	int h;
	cin >> h;
	int ans = 0;
	bitset<45> b(h);
	for (int i = 44; i >= 0; i--)
	{
		if (b[i])
		{
			ans = i;
			break;
		}
	}
	ans++;
	int x = 0, y = 1;
	while (ans--)
	{
		x += y;
		y *= 2;

	}
	cout << x << endl;
}



Measured memory_bytes: 4992