import java.util.*;
import java.math.*;
public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	}
}  import java.util.*; util.* java import java.math.*; math.* java public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	}
} Main static int x; x static int ans; ans public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	} main {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) long h = in.nextLong(); h in.nextLong() in.nextLong in long cur = 1; cur 1 long ans = 0; ans 0 while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		} h > 0 h 0 {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		} ans += cur ans cur h = (long) Math.floor(h / 2) h (long) Math.floor(h / 2) Math.floor Math h / 2 h 2 cur *= 2 cur 2 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	}
} public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	}
} Main
import java.util.*;
import java.math.*;
public class Main {
	static int x;
	static int ans;
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long h = in.nextLong();
		long cur = 1;
		long ans = 0;
		while(h > 0) {
			ans += cur;
			h = (long) Math.floor(h / 2);
			cur *= 2;
		}
		System.out.println(ans);
	}
} 