import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	}
}

 import java.io.*; io.* java import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; import static java.lang.Math.*; import static java.lang.Math.*; import static java.lang.Math.*; public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	}
} Main public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	} main {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	} BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String []s=br.readLine().split(" "); s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " long H = Long.parseLong(s[0]); H Long.parseLong(s[0]) Long.parseLong Long s[0] s 0 long sum=0 sum 0 ans=0 ans 0 ht; ht ht=(long)(log(H)/log(2)) ht (long)(log(H)/log(2)) log(H) log H log(2) log 2 ht+=1 ht 1 ans=(long)(pow(2,(ht))) ans (long)(pow(2,(ht))) pow 2 (ht) ans-=1 ans 1 out.println(ans) out.println out ans String []args args public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	}
} public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	}
} Main
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		long H = Long.parseLong(s[0]);
		long sum=0,ans=0,ht;
		
		ht=(long)(log(H)/log(2)); //to the base log 2
		
		ht+=1;//height of the binary tree
		
		//no of nodes of a BT
		
		ans=(long)(pow(2,(ht)));
		ans-=1;
		
		out.println(ans);
	
	}
}


