#include <bits/stdc++.h>
using namespace std;

int main() {
	long long h, res = 0, level = 1;
	cin >> h;
	while (h > 0) {
		res += level;
		h /= 2;
		level *= 2;
	}
	cout << res << endl;
	return 0;
}
