import java.util.Scanner;

public class Main {

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

		long H = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

		System.out.println(cnt);
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

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

		long H = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

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

		long H = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

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

		long H = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

		System.out.println(cnt);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc double val = Math.log(H) / Math.log(2); val Math.log(H) / Math.log(2) Math.log(H) Math.log Math H Math.log(2) Math.log Math 2 val = Math.floor(val) val Math.floor(val) Math.floor Math val long cnt = 0; cnt 0 for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		} int i = 0; int i = 0; i 0 i <= val i val i++ i++ i {
			cnt += Math.pow(2, i);
		} {
			cnt += Math.pow(2, i);
		} cnt += Math.pow(2, i) cnt Math.pow(2, i) Math.pow Math 2 i System.out.println(cnt) System.out.println System.out System System.out cnt 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 = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

		System.out.println(cnt);
		sc.close();
	}
} public class Main {

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

		long H = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

		System.out.println(cnt);
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

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

		long H = sc.nextLong();
		// Hのlog2をとる
		double val = Math.log(H) / Math.log(2);
		val = Math.floor(val);

		long cnt = 0;

		for (int i = 0; i <= val; i++) {
			cnt += Math.pow(2, i);
		}

		System.out.println(cnt);
		sc.close();
	}
}
