import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		System.out.println(ans);
	}
} import java.util.*; util.* java import java.lang.*; lang.* java public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		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 int count = 0; count 0 if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		} H>1 H 1 {

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		} for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		} int i=0; int i=0; i 0 i<40 i 40 i++ i++ i {
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		} {
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		} H = H/2 H H/2 H 2 count++ count if( H==1 ){
				break;
			} H==1 H 1 {
				break;
			} break; long ans = 1; ans 1 long a = 1; a 1 for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		} int i=0; int i=0; i 0 i<count i count i++ i++ i {
			a = a*2;
			ans += a;		
		} {
			a = a*2;
			ans += a;		
		} a = a*2 a a*2 a 2 ans += a ans a 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();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		System.out.println(ans);
	}
} public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		System.out.println(ans);
	}
} Main
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		int count = 0;
		if( H>1 ){

		for( int i=0; i<40; i++ ){
			H = H/2;
			count++;
			if( H==1 ){
				break;
			}
		}

		}
		long ans = 1;
		long a = 1;
		for( int i=0; i<count; i++ ){
			a = a*2;
			ans += a;		
		}
		System.out.println(ans);
	}
}
