import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	}

	static long attackNum(long X) {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	}

	static long attackNum(long X) {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	} main {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) System.out.println(attackNum(scanner.nextLong())) System.out.println System.out System System.out attackNum(scanner.nextLong()) attackNum scanner.nextLong() scanner.nextLong scanner String[] args args static long attackNum(long X) {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	} attackNum {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	} if (X == 1)
			return 1; X == 1 X 1 return 1; 1 return attackNum(X / 2) * 2+1; attackNum(X / 2) * 2+1 attackNum(X / 2) * 2 attackNum(X / 2) attackNum X / 2 X 2 2 1 long X X public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	}

	static long attackNum(long X) {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	}

	static long attackNum(long X) {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println(attackNum(scanner.nextLong()));

	}

	static long attackNum(long X) {
		if (X == 1)
			return 1;
		return attackNum(X / 2) * 2+1;
	}

}
