import java.util.*;

class Main {
	Scanner sc;
	long H;
	
	private void calc() {
		sc = new Scanner(System.in);
		H = sc.nextLong();
		long a = 0;
		long b = 1;
		while (H > 0) {
			H = H >>> 1;
			a += b;
			b = b << 1;
		}
		
		System.out.println(a);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
} import java.util.*; util.* java class Main {
	Scanner sc;
	long H;
	
	private void calc() {
		sc = new Scanner(System.in);
		H = sc.nextLong();
		long a = 0;
		long b = 1;
		while (H > 0) {
			H = H >>> 1;
			a += b;
			b = b << 1;
		}
		
		System.out.println(a);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
} Main Scanner sc; sc long H; H private void calc() {
		sc = new Scanner(System.in);
		H = sc.nextLong();
		long a = 0;
		long b = 1;
		while (H > 0) {
			H = H >>> 1;
			a += b;
			b = b << 1;
		}
		
		System.out.println(a);
	} calc {
		sc = new Scanner(System.in);
		H = sc.nextLong();
		long a = 0;
		long b = 1;
		while (H > 0) {
			H = H >>> 1;
			a += b;
			b = b << 1;
		}
		
		System.out.println(a);
	} sc = new Scanner(System.in) sc new Scanner(System.in) H = sc.nextLong() H sc.nextLong() sc.nextLong sc long a = 0; a 0 long b = 1; b 1 while (H > 0) {
			H = H >>> 1;
			a += b;
			b = b << 1;
		} H > 0 H 0 {
			H = H >>> 1;
			a += b;
			b = b << 1;
		} H = H >>> 1 H H >>> 1 H 1 a += b a b b = b << 1 b b << 1 b 1 System.out.println(a) System.out.println System.out System System.out a public static void main(String[] args) {
		new Main().calc();
	} main {
		new Main().calc();
	} new Main().calc() new Main().calc new Main() String[] args args
import java.util.*;

class Main {
	Scanner sc;
	long H;
	
	private void calc() {
		sc = new Scanner(System.in);
		H = sc.nextLong();
		long a = 0;
		long b = 1;
		while (H > 0) {
			H = H >>> 1;
			a += b;
			b = b << 1;
		}
		
		System.out.println(a);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}
