import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	}
} Main public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	} main {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	} try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		} {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long cnt = 0; cnt 0 long r = 1; r 1 while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			} h > 0 h 0 {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			} h /= 2 h 2 cnt = cnt + r cnt cnt + r cnt r r *= 2 r 2 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	}
} public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			long h = sc.nextLong();

			long cnt = 0;
			long r = 1;
			while (h > 0) {
				h /= 2;
				cnt = cnt + r;
				r *= 2;
			}
			System.out.println(cnt);
		}
	}
}
