import java.util.Scanner;

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

		// 入力値の取得
		long H = sc.nextLong();
		
		int count = 0;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		long H = sc.nextLong();
		
		int count = 0;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		long H = sc.nextLong();
		
		int count = 0;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		long H = sc.nextLong();
		
		int count = 0;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	} 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 long hp = H; hp H while (hp > 1) {
			count++;
			hp = hp / 2;
		} hp > 1 hp 1 {
			count++;
			hp = hp / 2;
		} count++ count hp = hp / 2 hp hp / 2 hp 2 long nodes = (long) Math.pow(2, count); nodes (long) Math.pow(2, count) Math.pow Math 2 count long sum = 0; sum 0 while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		} nodes >= 1 nodes 1 {
			sum += nodes;
			nodes = nodes / 2;
		} sum += nodes sum nodes nodes = nodes / 2 nodes nodes / 2 nodes 2 System.out.println(sum) System.out.println System.out System System.out sum sc.close() sc.close sc 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;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		// 入力値の取得
		long H = sc.nextLong();
		
		int count = 0;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	}
} Main
import java.util.Scanner;

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

		// 入力値の取得
		long H = sc.nextLong();
		
		int count = 0;
		long hp = H;
		while (hp > 1) {
			count++;
			hp = hp / 2;
		}
		
		// 結果の出力
		long nodes = (long) Math.pow(2, count);
		long sum = 0;
		while (nodes >= 1) {
			sum += nodes;
			nodes = nodes / 2;
		}
		System.out.println(sum);
		
		sc.close();
	}
}
