import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	}

	private static long attck(long h, long re, long deep) {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	}

	private static long attck(long h, long re, long deep) {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	}

} Main public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	} main {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long h = sc.nextLong(); h sc.nextLong() sc.nextLong sc long re = 0; re 0 long deep = 1; deep 1 re = attck(h, re, deep) re attck(h, re, deep) attck h re deep System.out.println(re - 1) System.out.println System.out System System.out re - 1 re 1 String[] args args private static long attck(long h, long re, long deep) {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	} attck {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	} if (h == 1) {
			return (long) Math.pow(2, deep);
		} h == 1 h 1 {
			return (long) Math.pow(2, deep);
		} return (long) Math.pow(2, deep); (long) Math.pow(2, deep) Math.pow Math 2 deep deep++ deep return attck(h / 2, (long) Math.pow(2, deep), deep); attck(h / 2, (long) Math.pow(2, deep), deep) attck h / 2 h 2 (long) Math.pow(2, deep) Math.pow Math 2 deep deep long h h long re re long deep deep public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	}

	private static long attck(long h, long re, long deep) {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	}

} public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	}

	private static long attck(long h, long re, long deep) {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 自分の得意な言語で
		// Let's チャレンジ！！

		Scanner sc = new Scanner(System.in);

		// モンスター体力
		long h = sc.nextLong();

		// 攻撃回数
		long re = 0;
		long deep = 1;

		// 初めの1匹を攻撃
		re = attck(h, re, deep);

		System.out.println(re - 1);

	}

	private static long attck(long h, long re, long deep) {
		if (h == 1) {
			return (long) Math.pow(2, deep);
		}
		deep++;
		return attck(h / 2, (long) Math.pow(2, deep), deep);
	}

}