import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = Long.parseLong(sc.next()); h Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc long sum = 0; sum 0 long pow = 1; pow 1 while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		} h >= 1 h 1 {
			h /= 2;
			sum += pow;
			pow *= 2;
		} h /= 2 h 2 sum += pow sum pow pow *= 2 pow 2 System.out.println(sum) System.out.println System.out System System.out sum sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	}
} Main
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h = Long.parseLong(sc.next());
		long sum = 0;
		long pow = 1;
		while (h >= 1) {
			h /= 2;
			sum += pow;
			pow *= 2;
		}

		System.out.println(sum);

		sc.close();
	}
}