// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
const double pi=acos(-1.0);

typedef pair<int, int> PII;

typedef vector<int> VI;

typedef vector<string> VS;

typedef vector<PII> VII;

typedef vector<VI> VVI;

typedef map<int,int> MPII;

typedef set<int> SETI;

typedef multiset<int> MSETI;

typedef long int li;

typedef unsigned long int uli;

typedef long long int ll;

typedef unsigned long long int  ull;

bool isPowerOfTwo (int x)
{
  /* First x in the below expression is
    for the case when x is 0 */
  return x && (!(x&(x-1)));
}
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
ll power(ll x, ll y, ll p)
{
    ll res = 1;      // Initialize result

    x = x % p;  // Update x if it is more than or
                // equal to p

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

// Returns n^(-1) mod p
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p);
}

// Returns nCr % p using Fermat's little
// theorem.
ll ncr(ll n, ll r,ll p)
{
   // Base case
   if (r==0)
      return 1;

    // Fill factorial array so that we
    // can find all factorial of r, n
    // and n-r
    ll fac[n+1];
    fac[0] = 1;
    for (ll i=1 ; i<=n; i++)
        fac[i] = fac[i-1]*i%p;

    return (fac[n]* modInverse(fac[r], p) % p *
            modInverse(fac[n-r], p) % p) % p;
}


int main()

{
ll n;
cin>>n;
ll x=1,m=2;
ll cnt=0;
while(n>0){
    n=n/m;
    cnt++;
}
x=1;
ll ans=0;
FOR(i,cnt){ans=m*ans+x;}
out(ans);



}

/*
 _____________§_§§_______§__§_____§§__§_________________
____________§___§§§____§___§__§§_____§_________________
____________§_____§§§_§____§_§§______§______§§_________
_____________§_______§§_____§________§__§§§§_§_________
_____________§_______________________§§§_____§_________
_____________§______________________________§__________
___§§§§§§_____§_____________________________§__________
____§______§§§_____________________________§___________
____§§_____________________________________§§§_________
_____§________________________________________§§§§_____
______§________________________________________ _§§_____
_______§_______________________________________§_______
_______§§____________________§_______________§§________
_______§_____________§§§§§§§§§_______________§_________
______§_____________§§§§§§§§§§§_______§_______§§_______
____§§____________§§§§§§§§§§§§§§________________§§_____
___§_____________§§§§§§____§§§§§§___§___§_________§§___
__§_____________§§§§§______§§§§§§____§__§§__________§__
§§_____________§§§§__§______§§§§§§§__§§__§________§§___
§_____________§§§§__§§______§§§§§§§__§§§_§§___§§§§_____
______________§§§__§_§§_____§§§§§§§§__§§§_§§__§________
_____________§§§___§§§_____§§§§§§§§§§_§§§§§§§__§_______
_____________§§____§§§____§§§§§§§§§_§§§§§§§§§___§______
§§§__________§_____§§§§_§§§§§§________§__§§§§§___§_____
___§§_______§§§____§§_§§§§§§§_____________§§§§§__§§____
____§_______§§§§___§_§§§§§__§________§____§§§§§§§§§§§§§
___§___§____§§§§§__§§§§§§__§______§§§________§__§§§§§§§
___§___§____§§§§§§§§§§§___§_____§§_________§_§§_§§§§§§§
__§____§____§§§§§§§§§§_________§§______§§§§§_§§__§§§§§§
_§_____§____§§§§§§§§§__________§______§_____§§§__§__§§§
_§____§§____§§§§§§§§§_______________________§§§__§_____
§______§____§§§§§§§§§§§§§____________________§§§_§_____
___§§§§_____§§§§§§_______§______________§§_§§§_§§______
______§__§__§§§§§§_§§§§§_____________________§§_§§_____
______§_§§__§§§§§_§§_§§_§_____________________§§_§§____
______§_§_§_§§§§§_§_§§§§§_________________§§§____§§____
______§_§_§_§§§§§_§_§§§§_____________________§____§____
______§§§_§§§§§§§_§§§§§§_______§_____§§§________§__§___
______§§§__§_§§§§__§§§§______§_____§§_________§§§_§§§__
______§_§___§_§_§___________§_____§___§§§_____§§__§§§§§
________§__§§____§______________§§__§§__§_____§§§_§§§§§
__________§____§_§§____________§§__§___§______§_§§_§§§§
_________§§_____§_§_§_________§§_§§__§§_______§__§§§_§§
_________§_______§_§__________§_§___§________§§__§§§___
_________________§§§_________§_§__§§_________§§__§§§§__
_________________§_§§_§_____§_§_§§___________§§_§§§§§__
__________________§§§§§_____§§§§_____§______§§§§§§§§§__
___________________§§§____________§§§______§§§§§§§§§§§_
____________________§§§__§________________§§§§§§§§§§§§§
_____________________§§§_§_______________§§§§§§§§§§§§§§
______________________§_§§______________§§§§§§§§§§§§§§§
________________________§§§____________§§§§§§§§§§§§§§§§
__________________________§§§§________§§§§§§§§§§§§§§§§§
_____________________________§§§§__§§§§§§§§§§§§§§§§§§§§
*/


Measured memory_bytes: 256