import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	}

} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	} main {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	} Scanner kb = new Scanner(System.in); kb new Scanner(System.in) long h = kb.nextLong(); h kb.nextLong() kb.nextLong kb long count = 0; count 0 long number = 0; number 0 while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		} h != 0 h 0 {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		} if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			} h == 1 h 1 {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} h = 0 h 0 count += (long) Math.pow(2, number) count (long) Math.pow(2, number) Math.pow Math 2 number number += 1 number 1 {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			} h = (long) Math.floor(h/2) h (long) Math.floor(h/2) Math.floor Math h/2 h 2 count += (long) Math.pow(2, number) count (long) Math.pow(2, number) Math.pow Math 2 number number += 1 number 1 System.out.println(count) System.out.println System.out System System.out count kb.close() kb.close kb String[] args args public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	}

} public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner kb = new Scanner(System.in);
		long h = kb.nextLong();
		long count = 0;
		long number = 0;
		while (h != 0) {
			if (h == 1) {
				h = 0;
				count += (long) Math.pow(2, number);
				number += 1;
			} else {
				h = (long) Math.floor(h/2);
				count += (long) Math.pow(2, number);
				number += 1;
			}
		}
		System.out.println(count);
		kb.close();
	}

}
