import java.math.*;
import java.util.*;
	
	public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		}
				
	} import java.math.*; math.* java import java.util.*; util.* java public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		}
				
	} Main public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		} main {
		
			Scanner sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long h2 = h; h2 h int num = 0; num 0 long sum = 0; sum 0 while(h2 >0 ) {
				h2 = h2/2;
				num++;
			} h2 >0 h2 0 {
				h2 = h2/2;
				num++;
			} h2 = h2/2 h2 h2/2 h2 2 num++ num for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			} int i=0; int i=0; i 0 i<num i num i++ i++ i {
				sum += Math.pow(2, i);
			} {
				sum += Math.pow(2, i);
			} sum += Math.pow(2, i) sum Math.pow(2, i) Math.pow Math 2 i 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 sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		}
				
	} public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		}
				
	} Main
import java.math.*;
import java.util.*;
	
	public class Main {
	
		public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			long h = sc.nextLong();
			long h2 = h;
			int num = 0;
			long sum = 0;
			
			
			while(h2 >0 ) {
				h2 = h2/2;
				num++;
			}
			
			for(int i=0;i<num;i++) {
				sum += Math.pow(2, i);
			}
			
			System.out.println(sum);
			
		}
				
	}