import java.util.Scanner;

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

	long H = sc.nextLong();

	long n = 0;
	do {
	    H = H / 2;
	    n++;
	} while (H > 0);

	long ans = 1;
	long floor = 1;
	for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	}

	System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	long H = sc.nextLong();

	long n = 0;
	do {
	    H = H / 2;
	    n++;
	} while (H > 0);

	long ans = 1;
	long floor = 1;
	for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	}

	System.out.println(ans);
    }
} Main public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);

	long H = sc.nextLong();

	long n = 0;
	do {
	    H = H / 2;
	    n++;
	} while (H > 0);

	long ans = 1;
	long floor = 1;
	for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	}

	System.out.println(ans);
    } main {
	Scanner sc = new Scanner(System.in);

	long H = sc.nextLong();

	long n = 0;
	do {
	    H = H / 2;
	    n++;
	} while (H > 0);

	long ans = 1;
	long floor = 1;
	for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	}

	System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long n = 0; n 0 do {
	    H = H / 2;
	    n++;
	} while (H > 0); H > 0 H 0 {
	    H = H / 2;
	    n++;
	} H = H / 2 H H / 2 H 2 n++ n long ans = 1; ans 1 long floor = 1; floor 1 for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	} long i = 1; long i = 1; i 1 i < n i n i++ i++ i {
	    ans += floor * 2;
	    floor *= 2;
	} {
	    ans += floor * 2;
	    floor *= 2;
	} ans += floor * 2 ans floor * 2 floor 2 floor *= 2 floor 2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.Scanner;

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

	long H = sc.nextLong();

	long n = 0;
	do {
	    H = H / 2;
	    n++;
	} while (H > 0);

	long ans = 1;
	long floor = 1;
	for (long i = 1; i < n; i++) {
	    ans += floor * 2;
	    floor *= 2;
	}

	System.out.println(ans);
    }
}