import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{
	
	
	public static void main(String[] args) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	}
} import java.util.ArrayList; ArrayList java.util import java.util.Collections; Collections java.util import java.util.Scanner; Scanner java.util public class Main{
	
	
	public static void main(String[] args) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	}
} Main public static void main(String[] args) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	} main {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	} Scanner s=new Scanner(System.in); s new Scanner(System.in) long n=s.nextLong(); n s.nextLong() s.nextLong s long ans=0; ans 0 for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		} int i=1; int i=1; i 1 i<=(Math.log(n)/Math.log(2))+1 i (Math.log(n)/Math.log(2))+1 (Math.log(n)/Math.log(2)) Math.log(n) Math.log Math n Math.log(2) Math.log Math 2 1 i++ i++ i {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		} {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		} ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i) ans ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i) ans (long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i) Math.pow Math 2 (Math.floor((Math.log(n)/Math.log(2))))+1-i (Math.floor((Math.log(n)/Math.log(2))))+1 (Math.floor((Math.log(n)/Math.log(2)))) Math.floor Math (Math.log(n)/Math.log(2)) Math.log(n) Math.log Math n Math.log(2) Math.log Math 2 1 i 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) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	}
} public class Main{
	
	
	public static void main(String[] args) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main{
	
	
	public static void main(String[] args) throws Exception {
		
		Scanner s=new Scanner(System.in);
		
		
		long n=s.nextLong();
		long ans=0;

		for(int i=1;i<=(Math.log(n)/Math.log(2))+1;i++) {
			ans=ans+(long)Math.pow(2, (Math.floor((Math.log(n)/Math.log(2))))+1-i);
			
		}
		System.out.println(ans);
		
	}
}