import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	} main {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long H = scan.nextLong(); H scan.nextLong() scan.nextLong scan long ans = 0; ans 0 long count = 1; count 1 while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		} true {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		} if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			} H == 1 H 1 {
				ans++;
				break;
			} ans++ ans break; {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			} H /= 2 H 2 count *= 2 count 2 ans += count ans count System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		long H = scan.nextLong();
		long ans = 0;
		long count = 1;
		while(true) {
			if (H == 1) {
				ans++;
				break;
			}
			else {
				H /= 2;
				count *= 2;			// 分裂するたびに倍攻撃が必要な累乗を保持
				ans += count;
			}
		}
		System.out.println(ans);
	}
}
