import java.util.Scanner;

//AtCoder Beginner Contest 153
//D - Caracal vs Monster
public class Main {

	public static long attack(long H) {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static long attack(long H) {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	}
} Main public static long attack(long H) {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	} attack {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	} if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		} H <= 1 H 1 return 1; 1 {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		} long ans = 1; ans 1 if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			} H % 2 == 0 H % 2 H 2 0 {
				ans += attack(H / 2) * 2;
			} ans += attack(H / 2) * 2 ans attack(H / 2) * 2 attack(H / 2) attack H / 2 H 2 2 {
				ans += attack((H - 1) / 2) * 2;
			} ans += attack((H - 1) / 2) * 2 ans attack((H - 1) / 2) * 2 attack((H - 1) / 2) attack (H - 1) / 2 (H - 1) H 1 2 2 return ans; ans long H H public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	} main {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = Long.parseLong(sc.next()); H Long.parseLong(sc.next()) Long.parseLong Long sc.next() sc.next sc sc.close() sc.close sc long ans = attack(H); ans attack(H) attack H System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {

	public static long attack(long H) {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	}
} public class Main {

	public static long attack(long H) {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	}
} Main
import java.util.Scanner;

//AtCoder Beginner Contest 153
//D - Caracal vs Monster
public class Main {

	public static long attack(long H) {
		if (H <= 1) return 1;
		else {
			long ans = 1;
			if (H % 2 == 0) {
				ans += attack(H / 2) * 2;
			} else {
				ans += attack((H - 1) / 2) * 2;
			}
			return ans;
		}
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long H = Long.parseLong(sc.next());
		sc.close();

		long ans = attack(H);
 		System.out.println(ans);
	}
}
