/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	static long solve(long a){
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	}
} import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main
{
	static long solve(long a){
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	}
} Main static long solve(long a){
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	} solve {
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	} if(a==0){
			return 0;
		} a==0 a 0 {
			return 0;
		} return 0; 0 return 1l+solve(a/2l)*2l; 1l+solve(a/2l)*2l 1l solve(a/2l)*2l solve(a/2l) solve a/2l a 2l 2l long a a public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	} main {
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan System.out.println(solve(a)) System.out.println System.out System System.out solve(a) solve a String[] args args public class Main
{
	static long solve(long a){
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	}
} public class Main
{
	static long solve(long a){
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	}
} Main
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	static long solve(long a){
		if(a==0){
			return 0;
		}
		return 1l+solve(a/2l)*2l;
	}
	
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan = new Scanner(System.in);
		long a = scan.nextLong();
		System.out.println(solve(a));
		// your code goes here
	}
}