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

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[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[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	}
} Main public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	} main {

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long h = scan.nextLong(); h scan.nextLong() scan.nextLong scan int ans = 0; ans 0 long two[] = new long[40]; two new long[40] 40 two[0] = 1 two[0] two 0 1 for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		} int i = 1; int i = 1; i 1 i < 40 i 40 i++ i++ i {
			two[i] = two[i-1]*2;
		} {
			two[i] = two[i-1]*2;
		} two[i] = two[i-1]*2 two[i] two i two[i-1]*2 two[i-1] two i-1 i 1 2 long twoadd[] = new long[40]; twoadd new long[40] 40 twoadd[0] = 1 twoadd[0] twoadd 0 1 for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		} int i = 1; int i = 1; i 1 i < 40 i 40 i++ i++ i {
			twoadd[i] = twoadd[i-1] + two[i];
		} {
			twoadd[i] = twoadd[i-1] + two[i];
		} twoadd[i] = twoadd[i-1] + two[i] twoadd[i] twoadd i twoadd[i-1] + two[i] twoadd[i-1] twoadd i-1 i 1 two[i] two i while((h /= 2) != 0)ans++; (h /= 2) != 0 (h /= 2) h 2 0 ans++ ans System.out.println(twoadd[ans]) System.out.println System.out System System.out twoadd[ans] twoadd ans String args[] args public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	}
} public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	}
} Main
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String args[]){

		Scanner scan = new Scanner(System.in);

		long h = scan.nextLong();
		
		int ans = 0;
		
		long two[] = new long[40];
		two[0] = 1;
		for(int i = 1; i < 40; i++){
			two[i] = two[i-1]*2;
		}
		
		long twoadd[] = new long[40];
		twoadd[0] = 1;
		for(int i = 1; i < 40; i++){
			twoadd[i] = twoadd[i-1] + two[i];
		}
		
		while((h /= 2) != 0)ans++;
		
		System.out.println(twoadd[ans]);
	}
}