import java.util.Scanner;

public class Main {


	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {


	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
} Main public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	} main {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	} Scanner sca = new Scanner(System.in); sca new Scanner(System.in) long h = sca.nextLong(); h sca.nextLong() sca.nextLong sca long times = 1L; times 1L long ans = 0L; ans 0L while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	} h != 0 h 0 {
		ans += times;
		h = h / 2;
		times *= 2;
	} ans += times ans times h = h / 2 h h / 2 h 2 times *= 2 times 2 System.out.println(ans) System.out.println System.out System System.out ans sca.close() sca.close sca String[] args args public class Main {


	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
} public class Main {


	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
} Main
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long times = 1L;
	long ans = 0L;

	while(h != 0) {
		ans += times;
		h = h / 2;
		times *= 2;
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
}