#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i , a , b) for(int i = a ; i <= b ; i ++)
#define P pair<int,int>
#define  sc(a) scanf("%d",&a)
#define pf(a) printf("%d ",a)
using namespace std;
signed main()
{
	ll a, b, c;
	c = 0;
	b = 1;
	cin >> a;
	while (a)
	{
		c += b;
		b *= 2;
		a = a / 2;
	}c += a;
	cout << c;
}









