import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();

		System.out.println(calc(h));
		scan.close();
	}

	private static long calc(long count) {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	}
} 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();

		System.out.println(calc(h));
		scan.close();
	}

	private static long calc(long count) {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	}
} Main public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();

		System.out.println(calc(h));
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();

		System.out.println(calc(h));
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long h = scan.nextLong(); h scan.nextLong() scan.nextLong scan System.out.println(calc(h)) System.out.println System.out System System.out calc(h) calc h scan.close() scan.close scan String... args args private static long calc(long count) {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	} calc {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	} return count <= 1 ? 1 : calc(count / 2) * 2 + 1; count <= 1 ? 1 : calc(count / 2) * 2 + 1 count <= 1 count 1 1 calc(count / 2) * 2 + 1 calc(count / 2) * 2 calc(count / 2) calc count / 2 count 2 2 1 long count count public class Main {
	public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();

		System.out.println(calc(h));
		scan.close();
	}

	private static long calc(long count) {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	}
} public class Main {
	public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();

		System.out.println(calc(h));
		scan.close();
	}

	private static long calc(long count) {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner scan = new Scanner(System.in);
		long h = scan.nextLong();

		System.out.println(calc(h));
		scan.close();
	}

	private static long calc(long count) {
		return count <= 1 ? 1 : calc(count / 2) * 2 + 1;
	}
}