import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		long H = Long.parseLong(line.split("\\s+")[0]);

		HashMap<Long, Long> mem = new HashMap<>();

		long res = dfs(H, mem);
		System.out.println(res);

		return;
	}

	public long dfs(long x, Map<Long, Long> mem) {
		if (x == 1) return 1;

		long key = x;
		if (mem.containsKey(key)) return mem.get(key);

		long res = 2 * dfs(x/2, mem) + 1;
		mem.put(key, res);

		return res;
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}

// f(x) = 2 * f( floor(x/2) ) + 1;
// f(1) = 1; import java.util.*; util.* java import java.lang.*; lang.* java import java.io.*; io.* java public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
} Main public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	} main {
		new Solution();
	} new Solution() String[] args args class Solution {
	Scanner scanner;
	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		long H = Long.parseLong(line.split("\\s+")[0]);

		HashMap<Long, Long> mem = new HashMap<>();

		long res = dfs(H, mem);
		System.out.println(res);

		return;
	}

	public long dfs(long x, Map<Long, Long> mem) {
		if (x == 1) return 1;

		long key = x;
		if (mem.containsKey(key)) return mem.get(key);

		long res = 2 * dfs(x/2, mem) + 1;
		mem.put(key, res);

		return res;
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
} Solution Scanner scanner; scanner public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	} Solution {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	} scanner = new Scanner(System.in) scanner new Scanner(System.in) while (scanner.hasNext()) {
			run_case();
		} scanner.hasNext() scanner.hasNext scanner {
			run_case();
		} run_case() run_case private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		long H = Long.parseLong(line.split("\\s+")[0]);

		HashMap<Long, Long> mem = new HashMap<>();

		long res = dfs(H, mem);
		System.out.println(res);

		return;
	} run_case {
		// scanner.nextLine();
		String line = scanner.nextLine();

		long H = Long.parseLong(line.split("\\s+")[0]);

		HashMap<Long, Long> mem = new HashMap<>();

		long res = dfs(H, mem);
		System.out.println(res);

		return;
	} String line = scanner.nextLine(); line scanner.nextLine() scanner.nextLine scanner long H = Long.parseLong(line.split("\\s+")[0]); H Long.parseLong(line.split("\\s+")[0]) Long.parseLong Long line.split("\\s+")[0] line.split("\\s+") line.split line "\\s+" 0 HashMap<Long, Long> mem = new HashMap<>(); mem new HashMap<>() long res = dfs(H, mem); res dfs(H, mem) dfs H mem System.out.println(res) System.out.println System.out System System.out res return; public long dfs(long x, Map<Long, Long> mem) {
		if (x == 1) return 1;

		long key = x;
		if (mem.containsKey(key)) return mem.get(key);

		long res = 2 * dfs(x/2, mem) + 1;
		mem.put(key, res);

		return res;
	} dfs {
		if (x == 1) return 1;

		long key = x;
		if (mem.containsKey(key)) return mem.get(key);

		long res = 2 * dfs(x/2, mem) + 1;
		mem.put(key, res);

		return res;
	} if (x == 1) return 1; x == 1 x 1 return 1; 1 long key = x; key x if (mem.containsKey(key)) return mem.get(key); mem.containsKey(key) mem.containsKey mem key return mem.get(key); mem.get(key) mem.get mem key long res = 2 * dfs(x/2, mem) + 1; res 2 * dfs(x/2, mem) + 1 2 * dfs(x/2, mem) 2 dfs(x/2, mem) dfs x/2 x 2 mem 1 mem.put(key, res) mem.put mem key res return res; res long x x Map<Long, Long> mem mem private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	} strToIntArray {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	} String[] vals = str.split("\\s+"); vals str.split("\\s+") str.split str "\\s+" int sz = vals.length; sz vals.length vals vals.length int[] res = new int[sz]; res new int[sz] sz for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    } int i=0; int i=0; i 0 i<sz i sz i++ i++ i {
	        res[i] = Integer.parseInt(vals[i]);
	    } {
	        res[i] = Integer.parseInt(vals[i]);
	    } res[i] = Integer.parseInt(vals[i]) res[i] res i Integer.parseInt(vals[i]) Integer.parseInt Integer vals[i] vals i return res; res String str str public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
} public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
} Main
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Scanner scanner;
	public Solution() {
		scanner = new Scanner(System.in);

		// scanner.nextLine();
		while (scanner.hasNext()) {
			run_case();
		}
	}
	private void run_case() {
		// scanner.nextLine();
		String line = scanner.nextLine();

		long H = Long.parseLong(line.split("\\s+")[0]);

		HashMap<Long, Long> mem = new HashMap<>();

		long res = dfs(H, mem);
		System.out.println(res);

		return;
	}

	public long dfs(long x, Map<Long, Long> mem) {
		if (x == 1) return 1;

		long key = x;
		if (mem.containsKey(key)) return mem.get(key);

		long res = 2 * dfs(x/2, mem) + 1;
		mem.put(key, res);

		return res;
	}

	private int[] strToIntArray(String str) {
	    String[] vals = str.split("\\s+");
	    int sz = vals.length;
	    int[] res = new int[sz];
	    for (int i=0; i<sz; i++) {
	        res[i] = Integer.parseInt(vals[i]);
	    }
	    return res;
	}
}

// f(x) = 2 * f( floor(x/2) ) + 1;
// f(1) = 1;
