import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	}


	public static long bin(long x) {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	}

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

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	}


	public static long bin(long x) {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	}

} Main public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	} main {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) long h = Long.parseLong(scanner.nextLine()); h Long.parseLong(scanner.nextLine()) Long.parseLong Long scanner.nextLine() scanner.nextLine scanner long ans = bin(h); ans bin(h) bin h System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static long bin(long x) {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	} bin {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	} long count = 0; count 0 if(x <= 1) {

			count = 1;

			return count;

		} x <= 1 x 1 {

			count = 1;

			return count;

		} count = 1 count 1 return count; count while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		} x > 1 x 1 {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		} if(x % 2 != 0) {

				x = x - 1;

			} x % 2 != 0 x % 2 x 2 0 {

				x = x - 1;

			} x = x - 1 x x - 1 x 1 x /= 2 x 2 count++ count return (long) ((Math.pow(2,count + 1)) - 1); (long) ((Math.pow(2,count + 1)) - 1) (Math.pow(2,count + 1)) Math.pow Math 2 count + 1 count 1 1 long x x public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	}


	public static long bin(long x) {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	}

} public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	}


	public static long bin(long x) {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	}

} Main
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		long h = Long.parseLong(scanner.nextLine());
		long ans = bin(h);
		System.out.println(ans);

	}


	public static long bin(long x) {

		long count = 0;

		if(x <= 1) {

			count = 1;

			return count;

		}



		while(x > 1) {

			if(x % 2 != 0) {

				x = x - 1;

			}

			x /= 2;
			count++;

		}

		return (long) ((Math.pow(2,count + 1)) - 1);

	}

}