import java.util.Scanner;

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

		long H = sc.nextLong();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	}
} 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();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	} main {
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) long H = sc.nextLong(); H sc.nextLong() sc.nextLong sc long hp = H; hp H long cnt = 1; cnt 1 long monster = 1; monster 1 while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		} true {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		} if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			} hp == 1 hp 1 {
				break;
			} break; {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			} hp /= 2 hp 2 monster *= 2 monster 2 cnt += monster cnt monster System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long H = sc.nextLong();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	}
} Main
import java.util.Scanner;

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

		long H = sc.nextLong();
		long hp = H;
		long cnt = 1;
		long monster = 1;
		while (true) {
			if (hp == 1) {
				break;
			}
			else {
				hp /= 2;
				monster *= 2;
				cnt += monster;
			}
		}
		System.out.println(cnt);
	}
}