import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	}
	
	static private long countTurn(long hp) {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	}
	
	static private long countTurn(long hp) {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	}
} Main public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	} main {
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	} try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		} {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		} Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc System.out.println(countTurn(h)) System.out.println System.out System System.out countTurn(h) countTurn h String[] args args static private long countTurn(long hp) {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	} countTurn {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	} if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		} hp == 1 hp 1 {
			return 1;
		} return 1; 1 {
			return 2 * countTurn(hp / 2) + 1;
		} return 2 * countTurn(hp / 2) + 1; 2 * countTurn(hp / 2) + 1 2 * countTurn(hp / 2) 2 countTurn(hp / 2) countTurn hp / 2 hp 2 1 long hp hp public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	}
	
	static private long countTurn(long hp) {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	}
} public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	}
	
	static private long countTurn(long hp) {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			long h = sc.nextLong();
			
			
			System.out.println(countTurn(h));

		}
			
	}
	
	static private long countTurn(long hp) {
		
		if ( hp == 1 ) {
			return 1;
		}
		else {
			return 2 * countTurn(hp / 2) + 1;
		}
	}
}