import java.util.Scanner;
 
public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
long h = scan.nextLong();
		
		long sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	}
} 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 sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	}
} Main public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
long h = scan.nextLong();
		
		long sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	} main {
		Scanner scan = new Scanner(System.in);
long h = scan.nextLong();
		
		long sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long h = scan.nextLong(); h scan.nextLong() scan.nextLong scan long sum = 1; sum 1 long x = 2; x 2 while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		} h != 0 h 0 {
			sum += x;
			x*=2;
			h/=2;
		} sum += x sum x x*=2 x 2 h/=2 h 2 x/=2 x 2 sum -=x sum x System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
long h = scan.nextLong();
		
		long sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	}
} public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
long h = scan.nextLong();
		
		long sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	}
} 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 sum = 1;
		long x = 2;
		
		while (h != 0) {
			sum += x;
			x*=2;
			h/=2;
		}
		x/=2;
		sum -=x;
		
		System.out.println(sum);
	}
}