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 multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		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 multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		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 multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		System.out.println(ans);

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

		long ans = 0;
		long multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		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 multi = 1; multi 1 for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		} int i = 1; int i = 1; i 1 h >= 1 h 1 i++ i++ i {
			ans += multi;
			multi *= 2;
			h /= 2;
		} {
			ans += multi;
			multi *= 2;
			h /= 2;
		} ans += multi ans multi multi *= 2 multi 2 h /= 2 h 2 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 multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		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 multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		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 multi = 1;
		for(int i = 1; h >= 1; i++) {
			ans += multi;
			multi *= 2;
			h /= 2;
		}

		System.out.println(ans);

	}

}