import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	System.out.println(ans);
        
	}
} import java.util.*; util.* java import java.lang.Math; Math java.lang public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	System.out.println(ans);
        
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	System.out.println(ans);
        
	} main {
		Scanner sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	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 = (int)(Math.log(h)/Math.log(2)) + 1; n (int)(Math.log(h)/Math.log(2)) + 1 (int)(Math.log(h)/Math.log(2)) Math.log(h) Math.log Math h Math.log(2) Math.log Math 2 1 long ans = (long)Math.pow(2,n) - 1; ans (long)Math.pow(2,n) - 1 (long)Math.pow(2,n) Math.pow Math 2 n 1 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 sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	System.out.println(ans);
        
	}
} public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	System.out.println(ans);
        
	}
} Main
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
  		
      	long h = sc.nextLong();
      	long n = (int)(Math.log(h)/Math.log(2)) + 1;
      	long ans = (long)Math.pow(2,n) - 1;
      	
      	System.out.println(ans);
        
	}
}
